#include <stdio.h>
#define len 100000
typedef struct q{
    char name[11];
    int time;
}q;
q pro[len];
int head,tail,n;
q enqueue(q x){
    pro[tail]=x;
    tail=(tail+1)%len;
}
q dequeue(void){
    head++;
    return pro[head-1];
}
int main(void){
    int n,max,total=0,i;
    q x;
    scanf("%d %d",&n,&max);
    for(i=0;i<n;i++)
        scanf("%s %d",pro[i].name,&pro[i].time);
    head=0,tail=n;
    while(head != tail){
        x=dequeue();
        if(x.time <= max){
            total+=x.time;
            printf("%s %d\n",x.name,total);
        }
        else{
            total+=max;
            x.time-=max;
            enqueue(x);
        }
    }
    return 0;
}