n = int(eval(input()))

a = [0]*n

for i in range(n):

    a[i] = int(eval(input()))

amax = sorted(a)[-1]

amax2 = sorted(a)[-2]

for i in range(n):

    if a[i] == amax:

        print(amax2)

    else:

        print(amax)

n = int(eval(input()))

a = [0]*n

for i in range(n):

    a[i] = int(eval(input()))

amax = sorted(a)[-2:]

for i in range(n):

    if a[i] == amax[1]:

        print((amax[0]))

    else:

        print((amax[1]))

n = int(eval(input()))
a = [0] * n
for i in range(n):
    a[i] = int(eval(input()))
amax = sorted(a)[-1]
amax2 = sorted(a)[-2]
for i in range(n):
    if a[i] == amax:
        print(amax2)
    else:
        print(amax)

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

-amax = sorted(a)[-1] -amax2 = sorted(a)[-2] +amax = sorted(a)[-2:] -    if a[i] == amax: -        print(amax2) +    if a[i] == amax[1]: +        print((amax[0])) -        print(amax) +        print((amax[1]))