n=int(input())

a=[int(input()) for _ in range(n)]

a.sort()

ans=[]

for i in range(3):

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

        ans.append(int(str(a[i])+str(a[j])))

        ans.append(int(str(a[j])+str(a[i])))

    ans.sort()

print((ans[2]))
n=int(input())

a=[int(input()) for _ in range(n)]

a.sort()

ans=[]

for i in range(3):

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

        ans.append(int(str(a[i])+str(a[j])))

        ans.append(int(str(a[j])+str(a[i])))

ans.sort()

print((ans[2]))
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
ans = []
for i in range(3):
    for j in range(i + 1, n):
        ans.append(int(str(a[i]) + str(a[j])))
        ans.append(int(str(a[j]) + str(a[i])))
    ans.sort()
print((ans[2]))

n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
ans = []
for i in range(3):
    for j in range(i + 1, n):
        ans.append(int(str(a[i]) + str(a[j])))
        ans.append(int(str(a[j]) + str(a[i])))
ans.sort()
print((ans[2]))

-    ans.sort() +ans.sort()