#include <iostream>
using namespace std;

// actually the main idea is easy to understand, cut the left subtree
// and right subtree separately and recursively call the postorder function to
// get the postorder of the tree
string postorder(string s, string t){	// s = preorder, t = inorder
	if (s.length() == t.length() && t.length() <= 1)
		return s;
	int index = t.find(s[0]);
	string preleft = s.substr(1, index);
	string preright = s.substr(index+1);
	
	string inleft = t.substr(0, index);
	string inright = t.substr(index+1);
	
	return postorder(preleft, inleft)+postorder(preright, inright)+s[0];
}

int main(){
	string s;
	while (getline(cin, s)){
		int t = s.find(" ");
		if (t == string::npos)
			puts("");
		else
			cout << postorder(s.substr(0, t), s.substr(t+1)) << endl;
	}
	return 0;
}
