
#include<stdio.h>
#include<string.h>
 
typedef struct {
  char name[15];
  int t;
}Process;
 
Process Q[1001];
int n, head = 0, tail = 0;
 
void set(Process x){
 
  if(tail == n){
    tail = 1;
  } else {
    tail += 1;
  }
 
 Q[tail] = x;
}
 
Process shead(){
  if(head == n){
    head = 1;
  } else {
    head++;
  }
  return Q[head];
}
 
int main(){
  int i, q, count = 0, time = 0;
  Process c;
 
  scanf("%d %d", &n, &q);
 
 for (i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
 
  while(count!=n){
    c = shead();
    if(c.t-q<=0){
      time += c.t;
      c.t = 0;
      count++;
      printf("%s %d\n",c.name ,time);
    } else if (c.t > 0){
      c.t -= q;
      time += q;    
      set(c);
    }
    
  }
  return 0;
}