The retired dean decided to test his memory by compiling lists of student groups at his faculty. For simplicity, he numbered the groups sequentially, starting from . However, he encountered a problem: while he clearly remembered the surnames of the group leaders and knew that no two students shared the same surname, he forgot which groups the other students belonged to. After some thought, he realized he could recall which students sat together during classes, implying they were in the same group. Using this information, write a program to determine which group each student belonged to.
The first line contains a single natural number —the number of groups, where 1 \leq N \leq 100.
The next lines each contain one surname: the surname of the group leader of the -th group (numbering starts from ).
The following line contains a single natural number —the number of pairs of students who, according to the dean's memory, studied in the same group, where 1 \leq K \leq 200\,000.
The next lines each contain two surnames separated by a space: pairs of students who studied in the same group.
Each surname is a string of lowercase Latin letters, with a length of no more than characters.
If the input data contains contradictions (for example, if a student is found to be in multiple groups), output the word Error on the first line.
Otherwise, output lines, each containing a student's surname and the group number they belonged to, separated by a space. If the group for a student cannot be determined from the input data, output instead of the group number. The surnames of the students in the resulting list should be sorted alphabetically.
Example 1