s = input().strip()

t = input().strip()

LS, LT = len(s), len(t)

dp = [[0]*(LT+1) for _ in range(LS+1)]

dp2 = [[(0, 0)]*(LT+1) for _ in range(LS+1)]

for i in range(LS):

    for j in range(LT):

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

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

            dp2[i+1][j+1] = (i, j)

        else:

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

            if dp[i][j+1] > dp[i+1][j]:

                dp2[i+1][j+1] = (i, j+1)

            else:

                dp2[i+1][j+1] = (i+1, j)

bb = []

a, b = (LS, LT)

while a > 0 and b > 0:

    if s[a-1] == t[b-1]:

        bb.append(s[a-1])

    a, b = dp2[a][b]



print(("".join(bb[::-1])))



s = " " + input().strip()

t = " " + input().strip()

LS, LT = len(s), len(t)

dp = [[0]*LT for _ in range(LS)]

for i in range(1, LS):

    for j in range(1, LT):

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

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

        else:

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

a, b = (LS-1, LT-1)

r = ""

while a > 0 and b > 0:

    if s[a] == t[b]:

        r+=s[a]

        a, b = a-1, b-1

    elif dp[a][b] == dp[a-1][b]:

        a -= 1

    else:

        b -= 1



print((r[::-1]))

s = input().strip()
t = input().strip()
LS, LT = len(s), len(t)
dp = [[0] * (LT + 1) for _ in range(LS + 1)]
dp2 = [[(0, 0)] * (LT + 1) for _ in range(LS + 1)]
for i in range(LS):
    for j in range(LT):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
            dp2[i + 1][j + 1] = (i, j)
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
            if dp[i][j + 1] > dp[i + 1][j]:
                dp2[i + 1][j + 1] = (i, j + 1)
            else:
                dp2[i + 1][j + 1] = (i + 1, j)
bb = []
a, b = (LS, LT)
while a > 0 and b > 0:
    if s[a - 1] == t[b - 1]:
        bb.append(s[a - 1])
    a, b = dp2[a][b]
print(("".join(bb[::-1])))

s = " " + input().strip()
t = " " + input().strip()
LS, LT = len(s), len(t)
dp = [[0] * LT for _ in range(LS)]
for i in range(1, LS):
    for j in range(1, LT):
        if s[i] == t[j]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
a, b = (LS - 1, LT - 1)
r = ""
while a > 0 and b > 0:
    if s[a] == t[b]:
        r += s[a]
        a, b = a - 1, b - 1
    elif dp[a][b] == dp[a - 1][b]:
        a -= 1
    else:
        b -= 1
print((r[::-1]))

-s = input().strip() -t = input().strip() +s = " " + input().strip() +t = " " + input().strip() -dp = [[0] * (LT + 1) for _ in range(LS + 1)] -dp2 = [[(0, 0)] * (LT + 1) for _ in range(LS + 1)] -for i in range(LS): -    for j in range(LT): +dp = [[0] * LT for _ in range(LS)] +for i in range(1, LS): +    for j in range(1, LT): -            dp[i + 1][j + 1] = dp[i][j] + 1 -            dp2[i + 1][j + 1] = (i, j) +            dp[i][j] = dp[i - 1][j - 1] + 1 -            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) -            if dp[i][j + 1] > dp[i + 1][j]: -                dp2[i + 1][j + 1] = (i, j + 1) -            else: -                dp2[i + 1][j + 1] = (i + 1, j) -bb = [] -a, b = (LS, LT) +            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) +a, b = (LS - 1, LT - 1) +r = "" -    if s[a - 1] == t[b - 1]: -        bb.append(s[a - 1]) -    a, b = dp2[a][b] -print(("".join(bb[::-1]))) +    if s[a] == t[b]: +        r += s[a] +        a, b = a - 1, b - 1 +    elif dp[a][b] == dp[a - 1][b]: +        a -= 1 +    else: +        b -= 1 +print((r[::-1]))