n = int(input())
dic = {}
for i in range(n):
key,value = map(int,input().split(' '))
dic[key] = dic.get(key,0)+value
for i in sorted(dic):
print(i,dic[i])

n = int(input())
dic = {}
for i in range(n):
key,value = map(int,input().split(' '))
dic[key] = dic.get(key,0)+value
for i in sorted(dic):
print(i,dic[i])