#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;
 
void enqueue(P x){
  Q[tail]=x;
  tail++;
  if(tail==LEN)tail=1;
}

P dequeue(){
  if(head==LEN)head=1;
  head++;
  return Q[head];
}


int main(){
  int elaps = 0, c;
  int i, q;
  //P u;
  head=1;
  tail=1;
  c=1;
  scanf("%d %d",&n,&q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
    enqueue(Q[i]);
  }
  
  /*printf("\n\n\n%d %d\n",n,q);
    for(i=1;i<=n;i++){
    printf("%s %d\n",Q[i].name,Q[i].t);
    }
    printf("\n\n\n");*/
  
  while(1){
    //printf("%d\n",Q[head].t);
    if(Q[head].t<=q){
      elaps=elaps+Q[head].t;
      printf("%s %d\n",Q[head].name,elaps);
      c++;
      dequeue();
    }
    
    else{
      Q[head].t=Q[head].t-q;
      elaps=elaps+q;
      enqueue(Q[head]);
      head++;
    }
    if(head==tail)break;
  }
   
  return 0;
}