import java.util.Scanner;
import java.util.Collections;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();//a
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < a; i++) {
            int x_i = in.nextInt();//key, x_i
            int y_i = in.nextInt();//value, y_i
            if (map.containsKey(x_i)) { //判断map集合里面是否包含x_i
                y_i = map.get(x_i) + y_i; //取出新的value,赋给y_i
                map.replace(x_i, y_i);//累加
            } else {
                map.put(x_i,
                        y_i);//如果判断没有重复的key值,就保留原来的key value值
            }


        }
        //new一个ArrayList集合,将map集合的keySet()取出来
        List<Integer> list = new ArrayList<>(map.keySet());
        Collections.sort(list);//默认为升序
        for (Integer integer :
                list) {//遍历list集合,用map集合的get()方法取出value值
            System.out.println(integer + " " + map.get(integer));
        }
    }
}