n = int(eval(input()))



a_list = []

for _ in range(n):

    a = int(eval(input()))

    a_list.append(a)

b_list = sorted(a_list, reverse=True)



for a in a_list:

    ans = b_list[0] if a != b_list[0] else b_list[1]

    print(ans)
n = int(eval(input()))

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

b_list = sorted(a_list, reverse=True)

for a in a_list:

    print((b_list[0] if a != b_list[0] else b_list[1]))
n = int(eval(input()))
a_list = []
for _ in range(n):
    a = int(eval(input()))
    a_list.append(a)
b_list = sorted(a_list, reverse=True)
for a in a_list:
    ans = b_list[0] if a != b_list[0] else b_list[1]
    print(ans)

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

-a_list = [] -for _ in range(n): -    a = int(eval(input())) -    a_list.append(a) +a_list = [int(eval(input())) for _ in range(n)] -    ans = b_list[0] if a != b_list[0] else b_list[1] -    print(ans) +    print((b_list[0] if a != b_list[0] else b_list[1]))