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

typedef struct{
  char name[10];
  int time;
}Process;

void enqueue(Process , int);
Process dequeue();

Process p[100000];
int Q_tail=0;
int Q_head=0;
int length=0;
int count=0;
int n=0;

int main(){ 
  int calc_time=0;
  int sum_time=0;
  int q=0;
  int i=0;
  Process rp;
  scanf("%d%d",&n,&q);

  for(i=0;i<n;i++)
    {
      scanf("%s%d",p[i].name,&p[i].time);
    }
  while(count<n){
    for(i=0;i<n;i++){
      if(p[i].time!=0){
	rp=dequeue();
	if(rp.time>q){
	  sum_time+=q;
	  enqueue(rp,rp.time-q);
	}
	else{
	  p[i].time=0;
	  sum_time+=rp.time;
	  printf("%s %d\n",p[i].name,sum_time);
	  count++;
	}
      }
    }
  }

  return 0;
}

Process dequeue(){
  Process x;
  x=p[Q_head];
  if(Q_head+1==n)
    Q_head=0;
  else Q_head++;
  return x;
}

void enqueue(Process Q, int t){
  p[Q_tail].time=t;
  //p[Q_tail].name=Q.name;
  strcpy(p[Q_tail].name,Q.name);
  if(Q_tail + 1 == n)
    Q_tail=0;
  else Q_tail++;
}

