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

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

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  tail++;
  n++;
  Q[tail]=x;
}

P dequeue(){
  n--;
  if(Q[head].t>0) enqueue(Q[head]);
  head++;

  return Q[head-1];
}


int main(){
  int elaps = 0;
  int i, q;
  scanf("%d %d", &n, &q);
  
  head =1;
  tail = n;
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  for(i=1;n>0;i++){
    
    if((Q[i].t-q)>0) {
      elaps=elaps+q;
      Q[i].t=Q[i].t-q;
      Q[i]=dequeue();
    }
    else if((Q[i].t-q)<=0){
      elaps=elaps+(q-(q-Q[i].t));
      Q[i].t=Q[i].t-q;
      printf("%s %d\n",Q[i].name,elaps);
      Q[i]=dequeue();
    }
  }  
  return 0;
}