a = int(input())
names = []
values = []

for i in range(a):
    x = input()
    m, n = x.split()
    if m in names:
        values[names.index(m)] += int(n) 
    else:
        names.append(m)
        values.append(int(n))

newnames = list(map(int, names))
comb = zip(newnames,values)
mydict = dict(sorted(comb))

for i, j in mydict.items():
    print(i, j)