import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
for (int i = 0;i<num;i++){
int key = sc.nextInt();
int value = sc.nextInt();
if(map.containsKey(key)){
map.put(key,map.get(key)+value);
}else {
map.put(key,value);
}
}
Object[] arr = map.keySet().toArray();
Arrays.sort(arr);
for (Object keys: arr
) {
System.out.println(keys+" "+map.get(keys));
}
}
}