N = int(eval(input()))

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



a = max(A)

b = sorted(A)[-2]

for i in A:

    print((b if i == a else a))

n = int(eval(input()))

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

a = max(l)

b = sorted(l)[-2]

for i in l:

  print((b if i == a else a))
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
a = max(A)
b = sorted(A)[-2]
for i in A:
    print((b if i == a else a))

n = int(eval(input()))
l = [int(eval(input())) for i in range(n)]
a = max(l)
b = sorted(l)[-2]
for i in l:
    print((b if i == a else a))

-N = int(eval(input())) -A = [int(eval(input())) for i in range(N)] -a = max(A) -b = sorted(A)[-2] -for i in A: +n = int(eval(input())) +l = [int(eval(input())) for i in range(n)] +a = max(l) +b = sorted(l)[-2] +for i in l: