Java Collections Students Subjects#9720

Java Collections Students Subjects

1 second
128 megabytes
Easy

Each student can take many subjects. Each subject can be taken by many students. Simulate the process of taking the subject.

Input

First line contains number . Each of the next lines have the form: Subject Student's_Surname. It means that subject Subject was taken by student with given surname. Then given number of queries . Each of the next lines contains either subject or surname.

Output

If the query contains subject, print in one line in ascending order the surnames of the students who took this subject. If the query contains surname, print in one line in ascending order the subjects taken by this student.

Examples

Example 1

Loading
Loading