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

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

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

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

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


int main(){
  int elaps=0,c=0;
  int i,q=0;
  P u;
  scanf("%d %d",&n,&q);
  head = 1;
  tail = n+1;
  P t[n+1];

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

  for(i=0; i < n; i++){
    printf("%s %d\n",t[i].name,t[i].t);
  }
  
  return 0;
}

