n = int(eval(input()))

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



b = sorted(a, reverse = True)

maximum = b[0]



for i in a:

    if i == maximum:

        print((b[1]))

    else:

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

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



b = sorted(a, reverse = True)

maximum = b[0]



for i in a: 

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

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

-    if i == maximum: -        print((b[1])) -    else: -        print(maximum) +    print((b[1] if i == maximum else maximum))