n=int(eval(input()))

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

s=sorted(l)

a,b=s[-1],s[-2]

for i in l: print(([b,a][a>i]))
n,*l=list(map(int,open(0)))

s=sorted(l)

for i in l: print((s[(i<s[-1])-2]))
n = int(eval(input()))
l = [int(eval(input())) for _ in range(n)]
s = sorted(l)
a, b = s[-1], s[-2]
for i in l:
    print(([b, a][a > i]))

n, *l = list(map(int, open(0)))
s = sorted(l)
for i in l:
    print((s[(i < s[-1]) - 2]))

-n = int(eval(input())) -l = [int(eval(input())) for _ in range(n)] +n, *l = list(map(int, open(0))) -a, b = s[-1], s[-2] -    print(([b, a][a > i])) +    print((s[(i < s[-1]) - 2]))