Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

C24E07CE - EC07C Replacing the Talking Pets (E)

Since a certain crustacean physician has consumed the last of the fish which were usually stuck in our ears and eased the communication of different intergalactic species by translating their words, a tender was published to create a machine translation system. A transtemporal outsourcing company turned out to be the lowest bidder (they were able to make such a low quote because they knew centuries such as the 21st where enthusiastic programmers worked on difficult problems for fun).

Your task is to create a program for generating dictionaries. The input for the program consists of a dictionary mapping the words of language A to language C, a dictionary mapping the words of language B to language C and a thesaurus that lists groups of synonymous word in language C. The program has to produce a dictionary for translating from language A to language B.

To be able to solve the problem, some things should be known about the languages spoken in the future. After the invention of time travel evolution reversed somehow and the human brain deteriorated severely. Human languages also became quite simple. There is a universal set of concepts. Each word in each language corresponds to a set of concepts that the word can refer to. We call this set the meaning set of the word (Mw). Two words are synonymous if their meaning sets are intersecting. The entries in a thesaurus simply corresponds to the concepts in the given language. The entry of the concept ci contains all the words that have the ith concept in their meaning sets (that is {w : ci in Mw}). You can assume that there are no words with empty concept sets. In a good dictionary from language X to language Y the entry for the word w (of language X) contains all the words in language Y that have an intersecting meaning set with w.

Input:

The first line contains three integers: K, L, and M. K is the number of entries in the A --> C dictionary, L is the number of entries in the B --> C dictionary, and M is the number of entries in the thesaurus for language C. The next K lines describe the A --> C dictionary: the first word of every line is the A language word, and the remaining words are the possible translations of this word in language C. The following L lines describe the B --> C dictionary in the same format. The last M lines contain the thesaurus for language C: every line contains a set of synonymous words that denote the same concept.

Output:

The output should contain one line for every word in language A, sorted in alphabetic order. The first word should be the word in language A. If the set of possible translations in language B can be determined unambiguously, then the remaining words should be the list of these possible translations in alphabetic order. Otherwise you have to output AMBIGUOUS as the second word in the line.

This is the electronic variant of the problem. Read more here about submitting solutions!

Example

Input:
2 1 2
apple alma
pear alma korte
apfel alma
alma
alma korte

Output:
apple apfel
pear AMBIGUOUS

Added by:Jacek DÄ…browski
Date:2009-02-13
Time limit:0.200s-2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 ASM32 BASH BF C CSHARP C++ 4.3.2 CPP C99 CLPS LISP sbcl LISP clisp D ERL FORTRAN HASK ICON ICK JAVA JS-RHINO LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST TEXT WHITESPACE
Resource:Challenge 24 2007 Electronic Contest

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.