n = int(input())
answer = []
for _ in range(n):
    (age,name) = map(str,input().split())
    answer.append((int(age),name))

for (i,j) in sorted(answer, key=lambda x:x[0]):
    print(i,j,end='\n')
102f7ce783fa496dca9fbf1398ca6f66a8e2396c
<mask token>

<mask token>
for _ in range(n):
    age, name = map(str, input().split())
    answer.append((int(age), name))
for i, j in sorted(answer, key=lambda x: x[0]):
    print(i, j, end='\n')

n = int(input())
answer = []
for _ in range(n):
    age, name = map(str, input().split())
    answer.append((int(age), name))
for i, j in sorted(answer, key=lambda x: x[0]):
    print(i, j, end='\n')

n = int(input())
answer = []
for _ in range(n):
    (age,name) = map(str,input().split())
    answer.append((int(age),name))

for (i,j) in sorted(answer, key=lambda x:x[0]):
    print(i,j,end='\n')