def merge_records(n):
    records = {}
    for _ in range(n):
        index, value = map(int, input().split())
        if index in records:
            records[index] += value
        else:
            records[index] = value
    for index in sorted(records.keys()):
        print(index, records[index])

n = int(input())
merge_records(n)