H. Horse Race
time limit per test
0.25 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

The Exponential Horse Racing company has been building larger and larger stadiums, allowing for many more horses than usual to participate in the same race. And, to facilitate filling those slots, it combines races of different tiers. That is, horses that are known to be much worse than others are allowed to race together, and spectators are allowed to bet on each of the small races that are happening. This also allows for horses that are between tiers to race in both tiers at once.

Paul is in charge of noting down the winner of each small race. To speed up that work, instead of noting down the full name of the winning horse, Paul notes down only its placement on the full race.

As an example, suppose that horses "a", "b", "c", "d" and "e" participated in a full race, and they reached the finish line in the order "e", "c", "a", "b" and "d". Hence a small race with horses "c" and "b" was won by "c", and then Paul would note down that the winner of the small race was the second horse, because "c" got that placement on the full race.

One day you got Paul's notes, but didn't have the full race results on hand. All you know is that there were no ties in the full race, and that every horse reached the finish line. Can you figure out the full race results by having only the description of each small race?

Input

The first line contains an integer $$$N$$$ ($$$2 \leq N \leq 300$$$) indicating the number of horses in the full race. The second line contains $$$N$$$ different strings representing the names of the horses. Each string has a length of up to three and is made of lowercase letters. The third line contains an integer $$$R$$$ ($$$1 \leq R \leq 10^5$$$) denoting the number of small races. For $$${i}={1}, {2}, \ldots, {R}$$$, the $$$i$$$-th of the next $$$R$$$ lines describes a small race with two integers $$$M_i$$$ ($$$2 \le M_i \le N$$$) and $$$W_i$$$ ($$$1 \le W_i \le N$$$), followed by $$$M_i$$$ different strings, indicating respectively the number of horses in the small race, the winner according to Paul's notes, and the names of the participating horses. It is guaranteed that $$$\sum_i M_i \le 10^5$$$.

Output

Output a single line with $$$N$$$ strings indicating the names of the horses in a valid order, that represents a possible result of the full race. It is guaranteed that there exists at least one solution. If there are multiple solutions, output any of them.

Examples
Input
5
a b c d e
3
4 2 a b c d
2 4 b d
2 2 c b
Output
e c a b d
Input
2
aaa b
3
2 1 aaa b
2 1 b aaa
2 1 aaa b
Output
aaa b