Problem C: Pre, in and post

Problem C: Pre, in and post

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1550  Solved: 648
[Submit][Status][Web Board]

Description

You are given the pre-order and in-order traversal of the binary tree, please find the post-order of this tree.

Input

The first line will be an integer \(T (1 \leq T \leq 10)\), which is the number of test cases.   
For each test data: 
The first line contains one integer \(N (1 \leq N \leq 10^3)\)  — the number of nodes of the tree
Then follows two lines:
The first line contains N integers ranging from 1 to N, indicating the pre-order traversal of the tree.
The second line contains N integers ranging from 1 to N, indicating the in-order traversal of the tree.

Output

For each case, contains one line with N integer, the post-order traversal of the tree.

Sample Input

1
5
1 2 4 3 5
2 4 1 5 3

Sample Output

4 2 5 3 1

HINT

[Submit][Status]