#include <iostream>
#include <string>
using namespace std;
struct TreeNode{
char data;
TreeNode *left,*right;
TreeNode(char c):data(c),left(nullptr),right(nullptr){}
};
int index(char a,string in){
int i;
for(i=0;i<in.length();i++){
if(in[i]==a)return i;
}
return 0;
}
TreeNode *BTree(string pre,string in,int len){
if(len<=0)return nullptr;
TreeNode *root;
root=new TreeNode(pre[0]);
int i;
i=index(pre[0], in);
root->left=BTree(pre.substr(1,pre.length()-1),in.substr(0,i),i);
root->right=BTree(pre.substr(i+1,pre.length()-i),in.substr(i+1,in.length()-i-1),len-i-1);
return root;
}//根据先序遍历结点来分割序列,分为左子树和右子树,递归生成树
void PostOrder(TreeNode *root){
if(root==nullptr)return;
PostOrder(root->left);
PostOrder(root->right);
cout<<root->data;
}//后序遍历的基础写法
int main() {
string a, b;
while (cin>>a>>b) {
if(a=="")break;
TreeNode *root=nullptr;
root=BTree(a,b,a.length());
PostOrder(root);
cout<<endl;
}
}
// 64 位输出请用 printf("%lld")