import java.util.*;

public class Main{

public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()){
        int num = Integer.parseInt(scanner.nextLine());
        if(num <= 0){
            System.exit(0);
        }
        Map<Integer,Integer> map = new TreeMap<>();
        while (num > 0){
            String[] lineNum = scanner.nextLine().split(" ");
            if(!map.containsKey(Integer.valueOf(lineNum[0]))){
                map.put(Integer.valueOf(lineNum[0]),Integer.valueOf(lineNum[1]));
            }else{
                map.replace(Integer.valueOf(lineNum[0]),map.get(Integer.valueOf(lineNum[0]))+Integer.parseInt(lineNum[1]));
            }
            num--;
        }
        Set<Map.Entry<Integer,Integer>> set = map.entrySet();
        set.stream().forEach(s -> System.out.println(s.getKey()+" "+s.getValue()));
    }
}

}