while True: try: n = int(input()) dic = {} for i in range(n): a = list(map(int,input().split())) if a[0] not in dic: dic[a[0]] = a[1] else: dic[a[0]] += a[1] #对字典按照键值进行排序 m = sorted(dic.items(),key = lambda x:x[0]) #遍历字典 for i in m: print(str(i[0]) + ' ' + str(i[1])) except: break