#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 100000

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

void enqueue(P);
P dequeue(void);

P queue[LEN];
int head = 0, tail = 0;

int main(){
  
  int elaps = 0, count = 0;
  int i, q, n;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", queue[i].name);
    scanf("%d", &queue[i].time);
    tail++;
  }

  while(1){
   if(count == n) break; 
     u = dequeue();   
     if((u.time-q) <= 0){
      elaps += u.time;
      printf("%s %d\n",u.name,elaps);
      count++;
    }

     else {
       u.time -= q;
       enqueue(u);
       elaps += q;
     }
    
   
  }
  
  return 0;
}

void enqueue(P x){
  int next = (tail+1)%LEN;
  if(tail+1 == head){
    printf("a\n");
    exit(2);
    }
  strcpy(queue[tail].name,x.name);
  queue[tail].time = x.time;
  tail = next;

}

P dequeue(){
  P val;
  if(head == tail) {
    printf("b\n");
    exit(3);
    }

  strcpy(val.name,queue[head].name);
  val.time = queue[head].time;
  head = (head+1)%LEN;

  return val;
  
}

