#include <stdio.h>
int main(){
    int n;
    int arr[500] = {0};
    int flag[500] = {-1};
    int p[500] = {0};
    int max = 0;            //记录最大赛道
    scanf("%d",&n);
    for(int i = 0; i < 500; i++) flag[i] = -1;
    for(int i = 0; i < n; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        int f = a / 500;     //计算在第几赛道,也就是标志
        int g = a % 500;     //计算在赛道的第几位,也就是标志下标
        if(f > max) max = f;
        if(flag[g] < 0){      //判断是否有键值
            arr[g] += b;
            flag[g] = f;
        }else if((500 * f + g + p[g]) == a){      //判断是否是同键值
            arr[g] += b;
        }else{                //键位被占向前移
            for(int j = g; j < 500; j++){
                if(flag[j] == -1 || (500 * f + g + p[g]) == a){
                    arr[j] += b;
                    flag[j] = f;
                    p[j] = j - g;
                }
            }
        }
    }
    for(int i = 0; i <= max; i++){
        for(int j = 0; j < 500; j++){
            if(flag[j] == i && arr[j] > 0){
                printf("%d %d\n",(500 * i + j + p[j]),arr[j]);
            }
        }
    }
    return 0;
}