A text file contains location information about international phone numbers. Each piece of information in the file spans two consecutive lines, a CODE line (maximum length 6 characters) and a NAME line (maximum length 20 characters). Here's an example.
32 BELGIUM 33 FRANCE 331 PARIS 34 CANARY ISLANDS 509 HAITI 51 PERU 680 PALAU 686 KIRIBATI 81 JAPAN
Using this file, the location of an international phone number can be found. The location of an international phone number is the NAME that follows the longest CODE in the file that is a prefix of the phone number. Note that more than one CODE in the file can be a prefix of a given number, such as is the case with the codes 33 and 331 here.
Using the above example, we would identify 349875750 to be in the Canary Islands, 3387657462 in France, 3314534383 in Paris, etc.
|Line 1||An integer N, representing the number of CODE,NAME pairs to follow. This number will not exceed 200.|
|Lines 2 to 2N+l||N CODE,NAME pairs as described above|
|Line 2N+2||An integer M, representing the number of phone numbers you must look up. This number will not exceed 10.|
|Last M lines||Phone numbers for which you must find locations.|
|M lines||The M locations of the phone numbers in the last M lines of the input file, in the same order as the numbers appeared. You may not assume that the location of each number can be found in the input file. If, for some phone number, there is no prefix of the number as a CODE, put UNKNOWN as the location in your output.|
4 32 BELGIUM 33 FRANCE 331 PARIS 34 CANARY ISLANDS 4 33245758584 5884739 34098767 331199888
FRANCE UNKNOWN CANARY ISLANDS PARIS