w = input()
wn = input()
def func(x1, x2):
if len(x1) > len(x2):
op = len(x2)
else:
op = len(x1)
xn = ['']
for i in range(op):
for j in range(i,op+1):
if op == len(x1):
if x1[i:j] in x2:
if len(x1[i:j]) > len(xn[-1]):
xn[-1] = x1[i:j]
else:
continue
elif op == len(x2):
if x2[i:j] in x1:
if len(x2[i:j]) > len(xn[-1]):
xn[-1] = x2[i:j]
else:
continue
print(xn[0])
func(w, wn)
wn = input()
def func(x1, x2):
if len(x1) > len(x2):
op = len(x2)
else:
op = len(x1)
xn = ['']
for i in range(op):
for j in range(i,op+1):
if op == len(x1):
if x1[i:j] in x2:
if len(x1[i:j]) > len(xn[-1]):
xn[-1] = x1[i:j]
else:
continue
elif op == len(x2):
if x2[i:j] in x1:
if len(x2[i:j]) > len(xn[-1]):
xn[-1] = x2[i:j]
else:
continue
print(xn[0])
func(w, wn)