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

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

void initialize(void);
void enqueue(P);
P dequeue(void);

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

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

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

  return 0;
}

void initialize(void){
  head = tail = 0;
}

int isEmpty(void){
  return head == tail;
}

int isFull(void){
  return head == (tail+1)%LEN;
}

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

P dequeue(void){
  P x;
  if(isEmpty()) return x;
  x = Q[head];
  if(head + 1 == LEN) head = 0;
  else head++;
  return x;
}