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