dict0 = {}
li0 = []
li1 = []
while True:
    try:
        lines = int(input())
        for i in range(lines):
            da = input()
            li = da.split(" ")
            n = int(li[0])
            v = li[1]
            if n not in li0:
                li0.append(n)
                dict0[n] = v
            else:
                t = dict0[n]
                dict0[n] = str(int(t) + int(v))
    except:
        break
for i in sorted(dict0.keys()):
    print(str(i) + " " + dict0[i])