s = int(input())
dic = {}
a = 1
while a <= s:
    k = [int(i) for i in input().split()]
    if k[0] not in dic.keys():
        dic[k[0]] = k[1]
    else:
        dic[k[0]] = k[1] + dic[k[0]]
    a += 1
p = sorted(int(i) for i in dic.keys())
for i in p:
    print(i, dic[i])