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

int main(int argc, char const *argv[])
{
  int n, q, head=0, timenow, count=0;
  // head means "queue head"
  // head ????????????????????§ queue ??????????????§??????
  char names[100000][11];
  int times[100000];
  int i;
  char answer[100000][11];
  int finished[100000];

  // ??\?????????
  scanf("%d%d", &n, &q);
  for(i=0;i<n;i++) {
    scanf("%s%d", names[i], &times[i]);
  }

  while(count!=n) {
    while(times[head]==0) {
      head++;
      if(head==n) {
        head=0;
      }
    }
    if(times[head]-q<=0) {
      timenow += times[head];
      strcpy(answer[count], names[head]);
      finished[count] = timenow;
      times[head] = 0;
      head++;
      count++;
      if(head==n) {
        head=0;
      }
    } else {
      times[head] -= q;
      timenow += q;
      head++;
    }
  }

  for(i=0;i<count;i++) {
    printf("%s %d\n", answer[i], finished[i]);
  }

  return 0;
}