//* Problem  : C - Compromise
//* Contest  : UzhNU Local
//* Origin   : Ulm-1997
//* Type     : Solution
//* Date     : 2008.02.04
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0
//* Algoritm : LCS

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

char dict[256][32];

int n, res;

int X[128], na;
int Y[128], nb;

char s[100];

int find(char *s)
{
	for (int i = 0; i < n; i++)
		if (!strcmp(dict[i], s))return i;
	strcpy(dict[n], s);
	n++;
	return n - 1;
}

int c[128][128], b[128][128];

int buildLCS(int *X, int n, int *Y, int m)
{
	int i, j;
	for (i = 1; i <= n; i++)
		c[i][0] = 0;
	for (j = 0; j <= m; j++)
		c[0][j] = 0;

	for (i = 1; i <= n; i++)
		for (j = 1; j <= m; j++)
		{
			if (X[i - 1] == Y[j - 1]) 
			{
				c[i][j] = c[i - 1][j - 1] + 1;
				b[i][j] = 1;
			}
			else if (c[i - 1][j] >= c[i][j - 1]) 
			{
				c[i][j] = c[i - 1][j];
				b[i][j] = 2;
			}
			else
			{
				c[i][j] = c[i][j - 1];
				b[i][j] = 3;
			}
		}
	return c[n][m];
}

int cnt;

void printLCS(int i, int j) 
{
	if (!i || !j) return;

	if (b[i][j] == 1) 
	{
		printLCS(i - 1, j - 1);
		if (cnt) putchar(' '); cnt++;
		printf("%s", dict[X[i-1]]);
	}
	else if (b[i][j] == 2)
		printLCS(i - 1,j);
	else
		printLCS(i,j - 1);
}

int main()
{
	while (!feof(stdin))
	{
		n = 0; na = nb = 0; s[0] = 0;
		while (scanf("%s", s) == 1 && s[0] != '#')
			X[na++] = find(s);
		if (!s[0]) break;
		while (scanf("%s", s) == 1 && s[0] != '#')
			Y[nb++] = find(s);
		res = buildLCS(X, na, Y, nb);
//		printf("%d\n", res);
		cnt = 0;
		printLCS(na, nb);
		putchar('\n');
	}
	return 0;
}