#include <iostream> //把每个单词看成一个字符,就是化成一维的求最长公共子序列
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
const int M = 105;
string str1[M],str2[M];
int len1,len2;
int dp[M][M];//dp[i][j]第一块前i个,第二块前j个,公共序列的长度
int path[M][M]; //dp[i][j]由三种情况得来,用1,2,3三种形式标记
void solve()
{
for(int i = 1; i <= len1; i++)
dp[i][0] = 0;
for(int i = 1; i <= len2; i++)
dp[0][i] = 0;
for(int i = 1; i <= len1; i++)
{
for(int j = 1; j <= len2; j++)
{
if(str1[i] == str2[j])
{
dp[i][j] = dp[i-1][j-1] + 1;
path[i][j] = 1;
}
else if(dp[i-1][j] > dp[i][j-1])
{
dp[i][j] = dp[i-1][j];
path[i][j] = 2;
}
else
{
dp[i][j] = dp[i][j-1];
path[i][j] = 3;
}
}
}
}
void output(int m,int n)
{
if(m == 0 || n == 0)
return ;
if(path[m][n] == 1)
{
output(m-1,n-1);
cout << str1[m]<<" ";
}
else if(path[m][n] == 2)
{
output(m-1,n);
}
else
output(m,n-1);
}
int main()
{
string str;
memset(dp,0,sizeof(dp));
while(cin >> str)
{
int num = 0;
if(str == "#")
break;
else
str1[++num] = str;
while(cin >> str)
{
if(str != "#")
str1[++num] = str;
else
break;
}
len1 = num;
num = 0;
while(cin >> str)
{
if(str != "#")
str2[++num] = str;
else
break;
}
len2 = num;
solve();
output(len1,len2);
cout << endl;
}
return 0;
}