#include <stdio.h>

typedef struct{
char name[10];
int time;
} process;

int main(){
int n,p,i=0,q;
int cnt=0,sum=0;
process Q[1000000];

scanf("%d%d",&n,&q);

for(i=0;i<n;i++){
scanf("%s%d",Q[i].name,&Q[i].time);
}
for(i=0;i<n;i++){
    Q[i].time -= q;

    if(Q[i].time <= 0){
        sum += Q[i].time + q;
        printf("%s %d\n",Q[i].name,sum);
    }
    else{
        Q[n] = Q[i];
        sum += q;
        n++;

    }

}
return 0;
}



