data = [] while True: try: n = input() d = {} while True: k,v = input().split(' ') if k in d.keys(): d[k] += int(v) else: d[k] = int(v) except (EOFError, KeyboardInterrupt): break for k,v in sorted(d.items(), key=lambda x:int(x[0])): print(k+' '+str(v))