Students
The retired dean, reminiscing about his days at the faculty, decided to test his memory by compiling lists of student groups. For simplicity, he numbered the groups sequentially, starting from 1. 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 reflection, he realized he could recall which students sat together during classes, indicating they were in the same group. Your task is to write a program that, using the information he has, determines which group each student belonged to.
Input
The first line contains a single natural number N—the number of groups, where 1 ≤ N ≤ 100.
The next N lines each contain one surname: the surname of the group leader of the i-th group (numbering starts from 1).
The following line contains a single natural number K—the number of pairs of students who, according to the dean's memory, studied in the same group, where 1 ≤ K ≤ 200000.
The next K 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 15 characters.
Output
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 M 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 0 instead of the group number. The surnames of the students in the resulting list should be sorted alphabetically.