Little Valentineliked playing with binary trees very much. Her favorite game was constructingrandomly looking binary trees with capital letters in the nodes.
This is an exampleof one of her creations:
D
/ \
/ \
B E
/ \ \
/ \ \
A C G
/
/
F
To record hertrees for future generations, she wrote down two strings for each tree: apreorder traversal (root, left subtree, right subtree) and an inorder traversal(left subtree, root, right subtree).
For the tree drawnabove the preorder traversal is DBACEGF and the inorder traversalis ABCDEFG.
She thought thatsuch a pair of strings would give enough information to reconstruct the treelater (but she never tried it).
Now, years later, looking again at the strings, she realized thatreconstructing the trees was indeed possible, but only because she never hadused the same letter twice in the same tree.
However, doing thereconstruction by hand, soon turned out to be tedious.
So now she asksyou to write a program that does the job for her!
The input filewill contain one or more test cases. Each test case consists of one linecontaining two strings preord and inord, representing the preorder traversaland inorder traversal of a binary tree. Both strings consist of unique capitalletters. (Thus they are not longer than 26 characters.)
Input isterminated by end of file.
For each testcase, recover Valentine's binary tree and print one line containing the tree'spostorder traversal (left subtree, right subtree, root).
DBACEGF ABCDEFG
BCAD CBAD
ACBFGED
CDAB