N=int(eval(input()))

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

m=sorted(a)[-1]

n=sorted(a)[-2]

for i in range(N):

  if a[i]==m:

    print(n)

  else:

    print(m)

    

N=int(eval(input()))

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

b=sorted(a)

m=b[-1]

n=b[-2]

for i in range(N):

  if a[i]==m:

    print(n)

  else:

    print(m)

    

N = int(eval(input()))
a = [int(eval(input())) for i in range(N)]
m = sorted(a)[-1]
n = sorted(a)[-2]
for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

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

-m = sorted(a)[-1] -n = sorted(a)[-2] +b = sorted(a) +m = b[-1] +n = b[-2]