#include <stdio.h>
#include <string.h>
int main()
{
 
  int time=0,i,head=0,tail,n,k,x[100000];
  char p[100000][10];
 
  scanf("%d %d",&n,&k);
  tail =n;
  for(i =0; i <n; i++) {
    scanf("%s %d",p[i],&x[i]);
  }
 
 
  while(tail != head) {
    if(x[head] > k) {
      time += k;
      x[head] -= k;
 
      strcpy(p[tail],p[head]);
      x[tail] = x[head];
      tail++;
      if(tail == 100000) {
        tail = 0;
      }
    }
    else{
      time += x[head];
      printf("%s %d\n",p[head],time);
    }
    head++;
    if(head == 100000) {
      head = 0;
    }
  }
  return 0;
}

