N = int(input())
AList = [input() for i in range(N)]

resultCash = {}

for i in range(N) :
    if AList[i] not in resultCash :
        resultCash[AList[i]] = max(AList[0:i] + AList[i+1:N])
    print(resultCash[AList[i]])