n = int(eval(input()))

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

a_sorted = sorted(a)[::-1][:2]

for an in a:

    print((a_sorted[an == a_sorted[0]]))
n = int(eval(input()))

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

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

print(('\n'.join(map(str, [a_sorted[an == a_sorted[0]] for an in a]))))
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_sorted = sorted(a)[::-1][:2]
for an in a:
    print((a_sorted[an == a_sorted[0]]))

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_sorted = sorted(a, reverse=True)[:2]
print(("\n".join(map(str, [a_sorted[an == a_sorted[0]] for an in a]))))

-a_sorted = sorted(a)[::-1][:2] -for an in a: -    print((a_sorted[an == a_sorted[0]])) +a_sorted = sorted(a, reverse=True)[:2] +print(("\n".join(map(str, [a_sorted[an == a_sorted[0]] for an in a]))))