#include <stdio.h>

#define N 100000

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

Queue Q[N];

int head=0,tail=0,n;


void enqueue(Queue x){
  Q[tail] = x;
  if(tail + 1 == n){
    tail = 0;
  }else{
    tail++;
  }
}

Queue dequeue(void){
  Queue r;
  r = Q[head];
  if(head + 1 == n){
    head = 0;
  }else{
    head++;
  }
  return r;
}


int main(void){
  int q,i,elaps=0,count=0;
  Queue data;

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

  
  return 0;
}
