n = int(eval(input()))

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



num = sorted(a, reverse=True)[:2]

for i in a:

  if i != num[0]:

    print((num[0]))

  else:

    print((num[1]))
n = int(eval(input()))

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



l = sorted(a, reverse=True)

x = l[0]

y = l[1]

for i in a:

  if i != x: print(x)

  else: print(y)
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
num = sorted(a, reverse=True)[:2]
for i in a:
    if i != num[0]:
        print((num[0]))
    else:
        print((num[1]))

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
l = sorted(a, reverse=True)
x = l[0]
y = l[1]
for i in a:
    if i != x:
        print(x)
    else:
        print(y)

-num = sorted(a, reverse=True)[:2] +l = sorted(a, reverse=True) +x = l[0] +y = l[1] -    if i != num[0]: -        print((num[0])) +    if i != x: +        print(x) -        print((num[1])) +        print(y)