import math

n = int(input())
#a, b = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
s = [input() for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

a = max(s)
b = sorted(s)[-2])

for i in range(n) :
    if (s[i] == a) :
        print(b)
    else :
        print(a)