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

typedef struct{
  char name[11];
  int time;
}DATA;



int main(){

  DATA *queue;
  int n,q,i,sumT=0,head=0,tail=0;

  scanf("%d%d",&n,&q);

  queue=(DATA *)malloc(sizeof(DATA)*(n+1));

  for(i=0;i<n;i++)scanf("%s%d",queue[i].name,&queue[i].time);

  tail=n;

  for(head=0;head!=tail;head++){
    if(head==n+1)head=0;
    if(q>=queue[head].time){
      sumT+=queue[head].time;
      printf("%s %d\n",queue[head].name,sumT);
    }else{
      sumT+=q;
      if(tail==n+1)tail=0;
      strcpy(queue[tail].name,queue[head].name);
      queue[tail].time=queue[head].time-q;
      tail++;
    }
  }

  free(queue);

  return 0;

}