Scanner sc = new Scanner(System.in);
Map<Integer,Integer> map = new TreeMap<> ();
int size = sc.nextInt();
for (int i = 0; i < size; i++) {
int ke = sc.nextInt();
int value = sc.nextInt();
if(map.containsKey(ke)) {
map.put(ke, value+map.get(ke));
}else {
map.put(ke, value);
}
}
Iterator it = map.entrySet().iterator();
while(it.hasNext()) {
Map.Entry<Integer, Integer> entry=(Entry<Integer, Integer>) it.next();
System.out.println(entry.getKey()+" "+entry.getValue());
}