#include<stdio.h>                                                               
#include<stdlib.h>
#define N 100000                 

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

pro ces[N];
int head=0,tail;

void enqueue (pro re){
    if(head==(tail+1)%N){
        fprintf(stderr,"over flow\n");
        exit(1);
    }
    ces[tail]=re;
    if(tail+1==N)tail=0;
    else tail++;

}

pro dequeue(void){

    pro de;

    de=ces[head];
    if(head+1==N)head=0;
    else head++;
    return de;
}


int main(){                                                                     
  int all=0,n,q,i,then;  
  pro de;                                                                                                                                      

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

    for(i=0;i<n;i++){
        scanf("%s%d",ces[i].name,&ces[i].time);
}
tail=n;
    while(1){
        de=dequeue();
        then=de.time-q;
        if(then>0){
            all+=q;
            de.time=then;
            enqueue(de);
     }
        else{
             all+=de.time;
            printf("%s %d\n",de.name,all);
            if(head==tail)break;
        }
    }   
return 0;
}                  
