#include<stdio.h>
#define LEN 1000050

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

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

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

P dequeue(){
  return Q[head];
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  head=1;
  tail=i-1;
  while(head!=tail+1){
    u=dequeue();

    //printf("head:%d tail:%d u.nam:%s u.t:%d elaps:%d\n",head,tail,u.name,u.t,elaps);
    
    if(head+1==LEN)head=1;
    else head++;
    
    if(u.t>q){
      u.t-=q;
      elaps+=q;
      enqueue(u);
    }
    else{
      elaps+=u.t;
      printf("%s %d\n",u.name,elaps);
    }
    if(elaps>1000000){
      //printf("..... (terminated because of the limitation)\n");
      break;
    }
  }
  
  return 0;
}

