N = int(input())

word = []

for _ in range(N):
    [x, y] = map(str,input().split())
    word.append([x,y])

word.sort()

for i in range(N):
     print(*(word[i]))
38cd9a434febd135242c786eef51e2ffaaf1688f
<mask token>

<mask token>
for _ in range(N):
    [x, y] = map(str, input().split())
    word.append([x, y])
word.sort()
for i in range(N):
    print(*word[i])

N = int(input())
word = []
for _ in range(N):
    [x, y] = map(str, input().split())
    word.append([x, y])
word.sort()
for i in range(N):
    print(*word[i])

N = int(input())

word = []

for _ in range(N):
    [x, y] = map(str,input().split())
    word.append([x,y])

word.sort()

for i in range(N):
     print(*(word[i]))