Woburn ECOO 1997

Arbitrage

INPUT FILE: arbit.in
OUTPUT FILE: arbit.out

Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US dollar buys 0.5 British pounds, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollars. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 * 10.0 * 21.0 = 1.05 US dollars, making a profit of 5 percent.

INPUT
The input will contain one or more test cases.
On the first line of each test case there is an integer n (1 <= n <= 30), representing the number of different currencies. The next n lines each contain the name of one currency.
The next line contains one integer m, representing the length of a table to follow. The last m lines each contain a real number r and two currency names c1 and c2, representing the exchange rate from the first currency to the second (meaning one c1 will buy r c2s). Exchanges which do not occur in the table are impossible.
Test cases are seoarated by blank lines. The input is terminated by a value of zero for n.

OUTPUT
For each test case, print one line telling whether arbitrage is possible or not in the format shown below.

Sample Input File

3
USDollar
BritishPound
FrenchFranc
3
USDollar 0.5 BritishPound
BritishPound 10.0 FrenchFranc
FrenchFranc 0.21 USDollar

3
USDollar
BritishPound
FrenchFranc
6
USDollar 0.5 BritishPound
USDollar 2.9 FrenchFranc
BritishPound 10.0 FrenchFranc
BritishPound 1.99 USDollar
FrenchFranc 0.09 BritishPound
FrenchFranc 0.19 USDollar

0

Output for Sample Input

Case 1: Yes
Case 2: No
Downloader failed! Response object 006~ASP 0159~Buffering Off~Buffering must be on.