#include<stdio.h>
typedef struct{
    char name[11];
    int time;
}queue;
int main(void){
    int n,q;
    scanf("%d %d",&n,&q);
    int size=2*n;
    queue Queue[size];
    int pre=0,rear=0,cnt=0;
    for(rear=0;rear<n;++rear){
        scanf("%s %d",Queue[rear].name,&Queue[rear].time);
    }
    while(pre!=rear){
        if(Queue[pre].time<=q){
            cnt+=Queue[pre].time;
            printf("%s %d\n",Queue[pre].name,cnt);
        }else{
            cnt+=q;
            Queue[pre].time-=q;
            Queue[rear]=Queue[pre];
            rear=(rear+1)%size;
        }
        pre=(pre+1)%size;
    }
    return 0;
}
