Cracking Tree Codes

No attempts yetTime limit1sMemory limit128 MB

Problem

Let V={1,2,,n}V = \{1, 2, \dots, n\} and E{{u,v}1u,vn}E \subset \{\{u, v\} \mid 1 \le u, v \le n\}. A tree T=(V,E)T = (V, E) is a graph that is connected and has exactly n1n - 1 edges. The figure below shows a tree T1T_1.

In T1T_1 we have V={1,2,3,4,5,6,7}V = \{1, 2, 3, 4, 5, 6, 7\} and E={{4,6},{2,6},{6,5},{3,5},{5,1},{1,7}}E = \{\{4, 6\}, \{2, 6\}, \{6, 5\}, \{3, 5\}, \{5, 1\}, \{1, 7\}\}.

Professor Minton found a way to encrypt a tree. The code of a tree is a sequence of n2n - 2 numbers from VV, built by repeating these three steps n2n - 2 times.

  1. In the part of the tree that is left, take the leaf (a vertex of degree 11) with the smallest number.
  2. Append the number of the only vertex adjacent to that leaf to the sequence.
  3. Delete that leaf from the tree.

After n2n - 2 rounds two vertices remain. The code of T1T_1 is 6,5,6,5,1\langle 6, 5, 6, 5, 1 \rangle.

A code sometimes arrives with a few of its numbers erased. Every erased position is written as the letter x. Given a tree and a code with erased numbers, write a program that recovers the erased numbers.

Input

The first line contains the number of test cases tt. (1t101 \le t \le 10)

Each test case takes three lines. The first line contains the number of vertices nn. (2n100002 \le n \le 10000) The second line contains 2n22n - 2 numbers separated by blanks that describe the tree. Reading two numbers at a time, the first pair is the first edge, the second pair is the second edge, and so on. The third line contains the code with erased numbers as n2n - 2 tokens. Each token is either a vertex number or the letter x for an erased position. When n=2n = 2 the third line is empty.

The numbers that were not erased agree with the code of the given tree. The sum of nn over all test cases is at most 3000030000.

Output

For each test case print one line holding the erased numbers in the order they appear in the input, separated by single blanks. If nothing was erased, print an empty line.