#include <stdio.h>
#include <string.h>

#define N 1000000

int main() {

  int i,j,n,q,a=0,time[N],count=0;
  char name[N][10];

  while(1) {
    scanf("%d %d",&n,&q);
    if(1<=n && n<=N) break;
  }

  for(i=0; count!=n; i++) {
    if(scanf("%s %d",name[i],&time[i])!=2) break;
  }

  for(j=0; count!=n; j++) {
    if(i==N) i = 0;
    if(time[j]>q) {
      a += q;
      time[i]	= time[j] - q;
      strcpy(name[i],name[j]);
      i++;
    }
    else {
      a += time[j];
      printf("%s %d\n",name[j],a);
      count++;
    }
  }

  return 0;
}