#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#pragma warning(disable:4996)
char a[30];
char b[30];
int pre = 0;
int zhong = 0;
void getPost(int begin,int end)
{
int pos;
char root;
if (begin == end)
{
printf("%c", b[begin]);
}
for (int i = 0; i < pre; i++)
{
int flag = 0;
for (int j = begin; j < end; j++)
{
if (a[i] == b[j])
{
pos = j;
root = b[j];
flag = 1;
}
}
if (flag)
break;
}
if (pos - 1 >= begin)
{
getPost(begin, pos - 1);
}
if (pos + 1 <= end)
{
getPost(pos + 1, end);
}
printf("%c", root);
}
int main()
{
freopen("input.txt", "r", stdin);
while (scanf_s("%s%s", a, b) != EOF)
{
pre = strlen(a);
zhong = strlen(b);
getPost(0,zhong);
}
}