while True:
try:
n = int(input())
dic = {}
while n > 0:
index,value = map(int,input().split(' '))
if index in dic:
dic[index] += value
else:
dic[index] = value
n -= 1
for i in sorted(dic):
print(i,dic[i])
except:
break
try:
n = int(input())
dic = {}
while n > 0:
index,value = map(int,input().split(' '))
if index in dic:
dic[index] += value
else:
dic[index] = value
n -= 1
for i in sorted(dic):
print(i,dic[i])
except:
break