import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
// while (in.hasNextInt()) { // 注意 while 处理多个 case
// int a = in.nextInt();
// int b = in.nextInt();
// System.out.println(a + b);
// }
int len = Integer.parseInt(in.nextLine());
Main.Map[] table = new Main.Map[len];
int index = 0;
// HashMap<int, int> map = new HashMap<>();
for (int i = 0; i < len; i++) {
String line = in.nextLine();
String[] entryStr = line.split(" ");
int[] entry = new int[2];
entry[0] = Integer.parseInt(entryStr[0]);
entry[1] = Integer.parseInt(entryStr[1]);
// Main main = new Main();
int hasInd = 0;
boolean has = false;
int ind = 0;
if (index == 0) {
Main.Map map = new Main.Map(entry[0], entry[1]);
table[ind] = map;
index++;
continue;
}
for (int j = index - 1; j >= 0; j--) {
if (table[j].getKey() == entry[0]) {
hasInd = j;
has = true;
break;
}
}
if (has) {
table[hasInd].setValue(table[hasInd].getValue() + entry[1]);
} else {
for (int k = index; k >= 0; k--) {
if (k == 0) {
ind = 0;
} else if (table[k - 1].getKey() > entry[0]) {
table[k] = table[k - 1];
} else {
ind = k;
break;
}
}
Main.Map map = new Main.Map(entry[0], entry[1]);
table[ind] = map;
index++;
}
}
for (int i = 0; i < index; i++) {
System.out.println(table[i].getKey() + " " + table[i].getValue());
}
}
static class Map {
private int k;
private int v;
public Map(int k, int v) {
this.k = k;
this.v = v;
}
public int getKey() {
return k;
};
public int getValue() {
return v;
};
public void setValue(int v) {
this.v = v;
}
}
}