s,t=eval(input()),eval(input())

m,n=len(s),len(t)

c=[[0]*(n+1) for _ in range(m+1)]

fro=[['']*(n+1) for _ in range(m+1)]

for i in range(1,m+1):

    for j in range(1,n+1):

        if s[i-1]==t[j-1]:

            c[i][j]=c[i-1][j-1]+1

            fro[i][j]='upper_left'

        elif c[i-1][j]>=c[i][j-1]:

            c[i][j]=c[i-1][j]

            fro[i][j]='above'

        else:

            c[i][j]=c[i][j-1]

            fro[i][j]='left'

x=''

a,b=m,n

while a>0 and b>0:

    if fro[a][b]=='upper_left':

        x+=s[a-1]

        a-=1;b-=1

    elif fro[a][b]=='above':

        a-=1

    else:

        b-=1

print((x[::-1]))
s,t=eval(input()),eval(input())

S,T=len(s),len(t)

dp=[[0]*(T+1) for _ in range(S+1)]

for i in range(1,S+1):

    for j in range(1,T+1):

        if s[i-1]==t[j-1]:

            dp[i][j]=dp[i-1][j-1]+1

        else:

            dp[i][j]=max(dp[i-1][j],dp[i][j-1])



i,j=S,T

ans=''

while min(i,j)>0:

        if dp[i][j]==dp[i][j-1]:

            j-=1

        elif dp[i][j]==dp[i-1][j]:

            i-=1

        else:

            ans+=s[i-1]

            i-=1 ; j-=1

print((ans[::-1]))
s, t = eval(input()), eval(input())
m, n = len(s), len(t)
c = [[0] * (n + 1) for _ in range(m + 1)]
fro = [[""] * (n + 1) for _ in range(m + 1)]
for i in range(1, m + 1):
    for j in range(1, n + 1):
        if s[i - 1] == t[j - 1]:
            c[i][j] = c[i - 1][j - 1] + 1
            fro[i][j] = "upper_left"
        elif c[i - 1][j] >= c[i][j - 1]:
            c[i][j] = c[i - 1][j]
            fro[i][j] = "above"
        else:
            c[i][j] = c[i][j - 1]
            fro[i][j] = "left"
x = ""
a, b = m, n
while a > 0 and b > 0:
    if fro[a][b] == "upper_left":
        x += s[a - 1]
        a -= 1
        b -= 1
    elif fro[a][b] == "above":
        a -= 1
    else:
        b -= 1
print((x[::-1]))

s, t = eval(input()), eval(input())
S, T = len(s), len(t)
dp = [[0] * (T + 1) for _ in range(S + 1)]
for i in range(1, S + 1):
    for j in range(1, T + 1):
        if s[i - 1] == t[j - 1]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
i, j = S, T
ans = ""
while min(i, j) > 0:
    if dp[i][j] == dp[i][j - 1]:
        j -= 1
    elif dp[i][j] == dp[i - 1][j]:
        i -= 1
    else:
        ans += s[i - 1]
        i -= 1
        j -= 1
print((ans[::-1]))

-m, n = len(s), len(t) -c = [[0] * (n + 1) for _ in range(m + 1)] -fro = [[""] * (n + 1) for _ in range(m + 1)] -for i in range(1, m + 1): -    for j in range(1, n + 1): +S, T = len(s), len(t) +dp = [[0] * (T + 1) for _ in range(S + 1)] +for i in range(1, S + 1): +    for j in range(1, T + 1): -            c[i][j] = c[i - 1][j - 1] + 1 -            fro[i][j] = "upper_left" -        elif c[i - 1][j] >= c[i][j - 1]: -            c[i][j] = c[i - 1][j] -            fro[i][j] = "above" +            dp[i][j] = dp[i - 1][j - 1] + 1 -            c[i][j] = c[i][j - 1] -            fro[i][j] = "left" -x = "" -a, b = m, n -while a > 0 and b > 0: -    if fro[a][b] == "upper_left": -        x += s[a - 1] -        a -= 1 -        b -= 1 -    elif fro[a][b] == "above": -        a -= 1 +            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) +i, j = S, T +ans = "" +while min(i, j) > 0: +    if dp[i][j] == dp[i][j - 1]: +        j -= 1 +    elif dp[i][j] == dp[i - 1][j]: +        i -= 1 -        b -= 1 -print((x[::-1])) +        ans += s[i - 1] +        i -= 1 +        j -= 1 +print((ans[::-1]))