import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
             //据题意可知此处需要用到TreeMap,利用自动排序的特性
             TreeMap<Integer,Integer> treeMap = new TreeMap<>();
             int length = scanner.nextInt();
             for(int i =0; i<length; i++){
                 int k = scanner.nextInt();
                 int v = scanner.nextInt();
                 if(treeMap.containsKey(k))
                     treeMap.put(k,treeMap.get(k)+v);
                 else
                     treeMap.put(k,v);
             }
            
            for(Map.Entry entry : treeMap.entrySet()){
                System.out.println(entry.getKey()+" "+entry.getValue());
            }
        }
    }
}