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

struct Process
 {
   char name[100];
   int t;
 };

struct Process Q[1000];

int seisuu;

void enqueue(struct Process x)
{
  int i;

  for(i=1;i<seisuu;i++) Q[i]=Q[i+1];

  Q[seisuu]=x;
}

struct Process dequeue(){ seisuu--;}

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