n = int(input()) map = {} for i in range(n): k, v = (int(x) for x in input().split(" ")) if k in map: map[k] += v else: map[k] = v #按key排序 map = sorted(map.items()) for k, v in map: print(k, v)