#include<stdio.h>
#include<string.h>
#define N1 100000
#define N2 10

struct queue{
  char name[N1][N2];
  int time[N1];
  int head;
  int tail;
};
int main(){
  int t,n,q,i;
  struct queue Queue;

  t=0;
  scanf("%d%d",&n,&q);
  Queue.head=0;
  Queue.tail=0;
  for(i=0;i<n;i++){
    scanf("%s%d",Queue.name[i],&Queue.time[i]);
    Queue.tail++;
  }
  i=0;
  
  while(Queue.head!=Queue.tail){
    Queue.time[i]-=q;
    if(Queue.time[i]<=0){
      Queue.head++;
      t=t+q+Queue.time[i];
      printf("%s %d\n",Queue.name[i],t);
    }
    else{
      strcpy(Queue.name[Queue.tail],Queue.name[i]);
      Queue.time[Queue.tail]=Queue.time[i];
      Queue.head++;
      Queue.tail++;
      t+=q;
    }
    i++;
    if(i>=N1){
      i=0;
    }
  }

  return 0;
}



