#include <iostream>
using namespace std;
string toPostorder(string& preorder,string& inorder){
if(preorder=="")return "";
char root=preorder[0];
int idx=inorder.find(root);
string inorderleft=inorder.substr(0,idx);
string inorderright=inorder.substr(idx+1);
string preorderleft=preorder.substr(1,inorderleft.length());
string preorderright=preorder.substr(inorderleft.length()+1);
return toPostorder(preorderleft,inorderleft)+
toPostorder(preorderright, inorderright)+root;
}
int main() {
string preorder,inorder;
while (cin >> preorder >> inorder) { // 注意 while 处理多个 case
cout<<toPostorder(preorder,inorder)<<endl;
}
}
// 64 位输出请用 printf("%lld")