SP10507 CHEESE - Cheese-rolling World Cup

Description

Nlogonian people is very excited about the event that will occur in the next year: the

Input Format

The input will consist of one or more test cases. Each test case starts with a line containing three integers N (1 numbered from 0 to N − 1, and the capital is the city number 0. Each of the N next lines contains the names of the cities, in increasing order of their numbers. Each name will contain only upper and lower case English letters, and its length will not exceed 30000. Each of the M next lines will describe the road network of the country. Each line will be in the form A B C (0 B with traffic flow limit C. There won’t be more than one road connecting a pair of cities in the same direction, and it will always be possible to go from the capital to any other city. The last test case will be followed by a line containg three zeros.

Output Format

For each test case, print one line with k - the number of chosen cities. Then, print k lines in the format n (pp) f , where n is a city name, pp is its pronunciation power and f is the maximum flow from the capital to the city. Print the cities in increasing order of their numbers. Also, if the capital is a chosen city, use f = 0. You may assume that k each test case.