N=int(input())I=[]for i in range(N): a,b=input().split() I.append([a,b])I=sorted(I,key=lambda x:(x[0][8],x[0][0]))for i in range(N): print(f"{I[i][0][8]}: {I[i][1]}")