Show Me the Money#4273

Show Me the Money

1 second
64 megabytes
Easy

Frank Marks works at the Business Office of a large company. His company has customers all over the world and must deal with many different currencies. Employees often come to the Business Office with requisitions for certain amounts of money, such as American dollars or Euros. If Frank has the cash on hand, he gives the employee exactly what they need; if he does not have enough of the particular currency requested, he substitutes it with another one. This is sometimes difficult because he may have many different currencies to choose from and would like to pick the one which allows him to get as close to the original requisition as possible without going under (he must provide at least the value requested). For example, suppose Frank has six different currencies - , , , , and - and he is aware of the following exchange rates:

23\ A = 17\ B

16\ C = 29\ E

5\ B = 14\ E

1\ D = 7\ F

If a requisition for comes in but Frank has less than available, he can substitute with either (equivalent to about ), (equivalent to about ) or (equivalent to about ). Thus, the best approximation available to him is . Note that Frank does not have enough information to find a relationship between currencies and or currencies and . Also, Frank only has at most units of any one currency in stock, so he could not satisfy a request for using currency and would need to use instead.

Determining the ideal substitute currency to use when he has completely run out of the requested currency is time consuming, so Frank would like a program to do the calculations for him.

Input

Each test case begins with a positive integer indicating the number of exchange rates. The next lines will be of the form

\text{val}_1 \text{name}_1 = \text{val}_2 \text{name}_2

where \text{name}_1 and \text{name}_2 are the names of two distinct currencies, and \text{val}_1 and \text{val}_2 are positive integers specifying the ratio between the two currencies. There will be no more than distinct currency names, and any two currencies will be paired together at most once. Currency names will consist of up to ten alphabetic characters. There will be no inconsistencies in the input (such as 1A = 2B, 1B = 2C and 1C = 2A). Following these lines will be a single line of the form

which specifies the amount (a positive integer not exceeding ) and the name of the currency requested. A line containing will follow the last test case.

Output

For each test case, print the case number and the closest approximation without going under the requested value assuming that Frank does not have any of the requested currency available but is fully in stock of all other currencies. There will be a unique answer for each problem instance.

Examples

Example 1

Loading
Loading