n = int(input()) d = {} # 用字典保存键和值 for _ in range(n): a, b = list(map(int,input().split())) #将输入的字符串,读成int if a in d: d[a] += b else: d[a] = b temp = sorted(d.items(), key=lambda x:x[0]) # 对字符串进行排序,是按照首字符排序的 for k, v in temp: print(k, v)