n = input() result = {} for i in range(int(n)): res = input().split() result[res[0]] = result.get(res[0], 0) + int(res[1]) result = sorted(result.items(), key=lambda x: int(x[0])) for i in result: print(i[0], str(i[1]))