#include<stdio.h>
#include<stdlib.h>

#define N 100000

typedef struct{
  char name[10];
  int time;
} ps;


int main(){
  ps dat[N];
  int i=0,j,x,y,head=0,tail,t=0;

  scanf("%d%d",&x,&y);
  
  tail = x-1;
  
  for(i = 0; i < x; i++){
    scanf("%s%d",dat[i].name,&dat[i].time);
  }

  printf("\n");
  

  for(i = 0;; i++){

    if(i == N)i = head;
    dat[i].time -= y;

    if(dat[i].time > 0){
      tail++;
      if(tail == N)tail = 0;
      dat[tail] = dat[head];
      t += y;

    }

    else if(dat[i].time <= 0){
      t += y + dat[i].time;
      
      printf("%s %d\n",dat[i].name,t);

      if(head == tail)break;

    }

    head ++;

    if(head == N)head = 0;
    
  }

  return 0;
}

