#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
  char c[100001][10],box[10],c2[100001][10];
  int time[100001];
  int i,j=0,n,q,top=0,tail=0,fcount=0,tcount=0,counta[100001];;
  scanf("%d%d",&n,&q);
  
  for(i=0;fcount != n;i++){
    if(i < n){ 
      tail++;
      scanf("%s%d",c[i],&time[i]);
      continue;
    }
    if(time[top] - q == 0 || time[top] - q < 0){
      tcount += time[top];
      time[top]=0;
      strcpy(c2[j],c[top]);
      counta[j]=tcount;
      j++;
      fcount++;
      if(top == n) top =0;
      else top++;
    }
      else{
	time[top]-=q;
	strcpy(c[tail],c[top]);
	time[tail]=time[top];
	tcount+=q;
	if(top == n) top = 0;
	else top++;
	if(tail == n) tail =0;
	else tail++;
      }  
  }
  for(i=0;i<n;i++) printf("%s %d\n",c2[i],counta[i]);
  return 0;
}
    