#输入key和value
n=int(input())
#初始化字典
dict1={}

for i in range(n):
    #将string转化为list
    list1=list(input().split()) 
    list2=list(map(lambda x:int(x), list1))
    #更新字典
    dict1[list2[0]] = dict1.get(list2[0], 0) + list2[1]

#输出排序后的字典
for key in sorted (dict1) : 
    print(key, dict1[key], end ="\n")