#include<stdio.h>
#define N 100000

typedef struct{
  char name[100];
  int time;
} queue;

queue q[100000];
int head=0,tail=0;

void enqueue(queue);
queue dequeue(void);

int main(){
  int n,i,quantum,count=0,sum=0;
  queue nt;

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

  for(i=0;i<n;i++){
    scanf("%s%d",nt.name,&nt.time);
    enqueue(nt);
  }

  while(1){
    if(head==tail) break;
    else if(q[head].time>quantum){
      nt=dequeue();
      nt.time=nt.time-quantum;
      enqueue(nt);
      sum=sum+quantum;
    }
    else{
      nt=dequeue();
      printf("%s %d\n",nt.name,nt.time+sum);
      sum=sum+nt.time;
    }
  }
  return 0;
}

void enqueue(queue a){
  q[tail]=a;
  if(tail+1==N){
    tail=0;
  }
  else tail++;
}

queue dequeue(){
  queue z;

  z=q[head];
  if(head+1==N){
    head=0;
  }
  else head++;
  return z;
}