#include<stdio.h>
#include<string.h>
 
typedef struct p{
  char name[100];
  int time;
}Process;
 
Process Que[100000];
int head, tail, n;
 
void enqueue(Process x){
  Que[tail] = x;
  tail = (tail + 1)%100000;
}
 
Process dequeue(){
  Process x = Que[head];
  head = (head + 1)%100000;
  return x;
}
 
int main(void){
  int i, n, q, e=0;
  scanf("%d %d\n", &n, &q);
  for (i=0;i<n;i++){
      Process que;
      scanf("%s %d", que.name, &que.time);
      enqueue(que);
  }

  while (head != tail){
      Process pro = dequeue();
      if (pro.time <= q){
          e += pro.time;
          printf("%s %d\n", pro.name, e);
      }
      else{
          e += q;
          pro.time -= q;
          enqueue(pro);
      }
  }
}