A=[int(eval(input())) for i in range(int(eval(input())))]



one=sorted(A)[-1]

two=sorted(A)[-2]



for i in A:

    print((one if i!=one else two))
A=[int(eval(input())) for i in range(int(eval(input())))]

B=sorted(A)

one=B[-1]

two=B[-2]

for i in A:print((one if i!=one else two))
A = [int(eval(input())) for i in range(int(eval(input())))]
one = sorted(A)[-1]
two = sorted(A)[-2]
for i in A:
    print((one if i != one else two))

A = [int(eval(input())) for i in range(int(eval(input())))]
B = sorted(A)
one = B[-1]
two = B[-2]
for i in A:
    print((one if i != one else two))

-one = sorted(A)[-1] -two = sorted(A)[-2] +B = sorted(A) +one = B[-1] +two = B[-2]