import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        // TreeMap保证index(key)是升序的
        Map<Integer, Integer> treeMap = new TreeMap<>();
        while (n-- > 0) {
            final int key = in.nextInt();
            final int value = in.nextInt();
            treeMap.compute(key, (k, v) -> v == null ? value : v + value);
        }
        treeMap.forEach((k, v) -> System.out.printf("%s %s\n", k, v));
    }
}