import java.util.Scanner;
import java.util.TreeMap;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    private static TreeMap<Integer, Integer> map = new TreeMap();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int a = 0, b = 0;
            for (int i = 0; i < n; i++) {
                a = in.nextInt();
                b = in.nextInt();
                if (map.get(a) == null) {
                    map.put(a, b);
                } else {
                    int s = map.get(a);
                    map.put(a, s + b);

                }
            }
            Object [] key = map.keySet().toArray();
            for(int i=0 ;i<map.keySet().size();i++)
            {
                System.out.println(key[i]+" "+map.get(key[i]));
            }
        }
    }
}