JasonTesla @ 2023-12-09 21:52:06
n=int(input())
nd=[]
def g(a):return a[1]
for i in range(n):
n,y,m,d=input().split()
if len(m)==1:m="0"+m
if len(d)==1:d="0"+d
nd.append([n,int(y+m+d)])
nd.sort(key=g,reverse=False)
for i in nd:print(i[0])