#include<stdio.h>

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

void enque(process);
process deque(void);

int head=0, tail=0;
process p[1000000];

int main(){
  int N,qtime;
  process P,Q;
  int stime=0;
  int i;

  scanf("%d%d",&N,&qtime);

  for(i=0;i<N;i++){
    scanf("%s%d",P.pn,&P.time);
    enque(P);
  }
  
  while(head!=tail){
    Q=deque();
    
    if(Q.time>qtime){
      Q.time-=qtime;
      stime+=qtime;
      enque(Q);
    }
    
    else{
      stime+=Q.time;
      printf("%s %d\n",Q.pn,stime);
     
    }
  }
  
  return 0;
}

void enque(process q){
  p[head]=q;
  head++;
}

process deque(void){
  tail++;
  return p[tail-1];
}

