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

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

int main(){
  int n,q,i,T=0,F;
  process* p;
  scanf("%d%d",&n,&q);

  p=(process *)malloc(sizeof(int)*n);
  
  for(i=0;i<n;i++){
    scanf("%s",p[i].name);
    scanf("%d",&p[i].time);
    p[i].flag=1;
  }
 
  while(1){
    F=0;
    for(i=0;i<n;i++){
      if(p[i].flag==1){
	if(p[i].time-q<=0){
	  T+=p[i].time;
	  printf("%s %d",p[i].name,T);
	  p[i].flag=0;
	}
	else{
	  p[i].time-=q;
	  T+=q;
	}
      }
      F+=p[i].flag;
    }
    if(F==0)
      break;
  }
  return 0;
}