#include <stdio.h>

#define TRUE 1
#define FALSE -1

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

int Q_tail=0;
int Q_head=0;
int length=0;
int count=0;

int main(){

  typedef struct{
    char name[10];
    int time;
    int number;
  }Process;
  
  int calc_time=0;
  int sum_time=0;
  int q=0;
  int i=0;
  int n=0;
  scanf("%d%d",&n,&q);
  int queue[n];
  Process p[n];
  length=sizeof(queue)/sizeof(int);
  for(i=0;i<n;i++)
    {
      scanf("%s%d",p[i].name,&p[i].time);
      enqueue(queue,p[i].time);
      p[i].number=i;
    }
  while(count<n){
    for(i=0;i<n;i++){
      if(p[i].time!=0){
	calc_time=dequeue(queue);
	if(calc_time>q){
	  p[i].time=calc_time-q;
	  sum_time+=q;
	  enqueue(queue,p[i].time);
	}
	else{
	  p[i].time=0;
	  sum_time+=calc_time;
	  printf("%s %d",p[i].name,sum_time);
	  printf("\n");
	  count++;
	}
      }
    }
  }

  return 0;
}

int dequeue(int *Q){
  int x;
  x=Q[Q_head];
  if(Q_head+1==length)
    Q_head=0;
  else Q_head=Q_head+1;
  return x;
}

void enqueue(int *Q, int t){
  Q[Q_tail]=t;
  if(Q_tail + 1 >= length)
    Q_tail=0;
  else Q_tail=Q_tail+1;
}

