N = int(eval(input()))

A = []

for i in range(N):

    A.append(int(eval(input())))

    

As = sorted(A, reverse=True)

for j in A:

    if j == As[0]:

        print((As[1]))

    else:

        print((As[0]))
N = int(eval(input()))

A = []

for _ in range(N):

    A.append(int(eval(input())))

Af = sorted(A, reverse=True)

for a in A:

    if a == Af[0]:

        print((Af[1]))

    else:

        print((Af[0]))
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
As = sorted(A, reverse=True)
for j in A:
    if j == As[0]:
        print((As[1]))
    else:
        print((As[0]))

N = int(eval(input()))
A = []
for _ in range(N):
    A.append(int(eval(input())))
Af = sorted(A, reverse=True)
for a in A:
    if a == Af[0]:
        print((Af[1]))
    else:
        print((Af[0]))

-for i in range(N): +for _ in range(N): -As = sorted(A, reverse=True) -for j in A: -    if j == As[0]: -        print((As[1])) +Af = sorted(A, reverse=True) +for a in A: +    if a == Af[0]: +        print((Af[1])) -        print((As[0])) +        print((Af[0]))