#include<cstdio>
#include<iostream>
#include<string>
using namespace std;

struct BT
{
	char data;
	BT *lchild,*rchild;
};

BT *build(string preorder,string inorder)
{
	BT *root;
	int p;
	if(!preorder.length())
		root=NULL;
	else
	{
		root=new BT;
		root->data=preorder[0];
		p=inorder.find(root->data);
		root->lchild=build(preorder.substr(1,p),inorder.substr(0,p));
		root->rchild=build(preorder.substr(1+p),inorder.substr(p+1));
	}
	return root;
}

void postorder(BT *root)
{
	if(root)
	{
		postorder(root->lchild);
		postorder(root->rchild);
		putchar(root->data);
	}
}

int main()
{
	string preorder,inorder;
	BT *root;
	while(cin>>preorder>>inorder)
	{
		root=build(preorder,inorder);
		postorder(root);
		printf("\n");
	}
	return 0;
}
/**************************************************************
	Problem: 2121
	User: admin
	Language: C++
	Result: Accepted
	Time:9 ms
	Memory:2080 kb
****************************************************************/