#include<stdio.h>
#include<stdlib.h>
#define N
int Q[];
void enqueue(int);
void dequeue(void);
int head=0,tail,n;
char name[100001][10];
int time[100001];

void dequeue(){
  int x;
  if(head+1 == n) head = 0;
  else head = head + 1;
}

void enqueue(int x){
  time[tail]=time[x];
  strcpy(name[tail],name[x]);
  if(head+1 == n) tail = 0;
  else tail++;
}


main(){
  int q,i,total=0;
  scanf("%d %d",&n,&q);
  for(tail=0;tail<n;tail++){
    scanf("%s %d",name[tail],&time[tail]);
  }
  while(head != tail){
    time[head] -= q;
    if(time[head]>0){
      total += q;
      dequeue();
      if(head - 1 != -1) enqueue(head - 1);
      else enqueue(n-1);
    }
    else {
      total += time[head] + q;
      printf("%s %d\n",name[head],total);
      head++;
    } 
  }
  return 0;
}