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

typedef struct{
  char c[20];
  int time;
}process;

process *make_process(){
  process *p;
  p=malloc(sizeof(process));
  p->time=0;
  return p;
}

typedef process data;
#define success 1
#define failure 0


typedef struct{
  int size;
  int head;
  int tail;
  data **data;
}queue;

queue *make_queue(int queue_size){
  queue *p;
  p=malloc(sizeof(queue));
  p->data=malloc(queue_size*sizeof(data *));
  p->size=queue_size;
  p->head=0;
  p->tail=0;
  return p;
}

int enque(queue *Q,data *x){
  if((Q->tail+1)%(Q->size +1) ==Q->head) return failure;
  else{
    Q->data[Q->tail]=x;
    Q->tail=(Q->tail+1)%(Q->size +1);
    return success;
  }
}

int deque(queue *Q,data **x){
  if(Q->head==Q->tail) return failure;
  else{
    *x=Q->data[Q->head];
    Q->head=(Q->head+1)%(Q->size+1);
    return success;
  }
}




int main(){
  int i,n,q,time=0;
  process **P;
  queue *Q;
  scanf("%d %d",&n,&q);
  P=malloc(n*sizeof(process *));
  Q=make_queue(n);
  for(i=0;i<n;i++){
    P[i]=make_process();
    scanf(" %s%d",P[i]->c,&(P[i]->time));
    enque(Q,P[i]);
  }
  process **x;
  x=malloc(sizeof(process *));
  /**x=make_process();*/
  while(Q->head!=Q->tail){
    deque(Q,x);
    if((*x)->time <= q){
      time+=(*x)->time;
      printf("%s %d\n",(*x)->c,time);
    }
    else{
      (*x)->time-=q;
      enque(Q,*x);
      time+=q;
    }
  }
  return 0;
} 
  
  
  