#include <stdio.h>
#include <stdlib.h>
#define Max 107000
typedef struct {
  char name[10];
  int time;
} process;

int main(){
  process dat1[Max];
  int i,j,tmp,a,b,head=0,tail,tim=0;

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

  for (i = 0;;i++){
    if(i ==Max)
      i =head;
    dat1[i].time -= b;
    if(dat1[i].time > 0){
      tail++; 
if(tail==Max)
  tail =0;
      dat1[tail] = dat1[head]; 
      tim += b;
    
    }
    else if(dat1[i].time <= 0){
      tim += b + dat1[i].time;
  printf("%s %d\n",dat1[i].name,tim);
    if(head == tail)break;
    }

  

 head++; 
if(head==Max)
  head =0;
  }


return 0;
}


	 
	 
    

    
  