for i in sorted([input().replace(" iti"," A") for _ in range(int(input()))]):print(i.replace("A","iti"))