Given the preorder and inorder traversals of a binary tree, show the postorder traversal of the binary tree.
For example, let A B D E F C G be the preorder traversal and D B F E A G C be the inorder traversal of a binary tree, the postorder traversal of the binary tree is D F E B G C A.
The input contains m test cases. The first line of input contains a single integer (m) representing the number of test cases. Each test case begins with a line containing an integer n, 1 ≤ n ≤ 26, indicating the number of nodes in a binary tree. The preorder and inorder traversals of the binary tree are given in the next two lines – the 1st line is the preorder traversal, and the 2nd line is the inorder traversal. The nodes of the binary tree are denoted by upper-case letters.
Output should contain m lines if there are m test cases of input data. Each line contains the postorder traversals for each test case.
範例輸入 1
3 7 A B D E F C G D B F E A G C 12 A B C D E F G H I J K L L K J I H G F E D C B A 17 Z A G H U Y B T F D W X C R S E V A G H U Z T W D F B Y C R S V E X
範例輸出 1
D F E B G C A L K J I H G F E D C B A U H G A W D F T B V E S R C X Y Z
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.