#include <iostream>
#include <fstream> 

using namespace std;

int main()
{
	ofstream output;
	output.open("OUT5.txt");
	
	for (int i = 0; i < 5; i++)
	{
		output << 500 << endl;
	}

	output.close();
}
/*




#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int n;
string a[20];
string b[20];
int cost[20];
int numPaths = 0;
int ttlCost[20];

int findCost(string arrival, int num)
{
	for (int i = (num + 1); i < n; i++)
	{
		if (a[i] == arrival && b[i] != "SEA")
		{
			ttlCost[num] += cost[i];
			ttlCost[num] = findCost(b[i], i);
		}
		else if (a[i] == arrival && b[i] == "SEA")
		{
			ttlCost[num] += cost[i];
			return ttlCost[num];
		}
	}
	return ttlCost[num];
}


int main()
{
	ifstream input;
	ofstream output;

	input.open("DATA5.txt");
	output.open("OUT5.txt");

	
	for (int z = 0; z < 5; z++)
	{
		input >> n;
		
		for (int i = 0; i < n; i++)
		{
			input >> a[i] >> b[i] >> cost[i];
		}

		for (int i = 0; i < n; i++)
		{
			if (a[i] == "YYZ")
			{
				numPaths += 1;
			}
		}

		int numPassed = 0;
		while (numPassed <= numPaths)
		{
			for (int i = numPassed; i < n; i++)
			{
				if (a[i] == "YYZ")
				{
					if (b[i] == "SEA")
					{
						ttlCost[i] += cost[i];
					}
					else
					{
						numPassed = i;
						ttlCost[i] += cost[i];
						ttlCost[i] = findCost(b[i], i);
					}
				}
			}
		}

		int min = 1000000;
		for (int i = 0; i < numPaths; i++)
		{
			if (ttlCost[i] < min)
			{
				ttlCost[i] = min;
			}
		}

		output << min;
	}

	input.close();
	output.close();
}
*/
