#include<stdio.h>
#include<string.h>
 
typedef struct p{
  char name[100];
  int time;
}Process;
 
Process Que[10000];
int head, tail, n;
 
void enqueue(Process x){
  Que[tail] = x;
  tail = (tail + 1)%10000;
}
 
Process dequeue(){
  Process x = Que[head];
  head = (head + 1)%10000;
  return x;
}
 
int min(int a, int b){ 
  return a < b ? a:b;
}
 
int main(void){
  int e = 0;
  int i, q, c;
  Process u;
  head = 1;
  tail = n+1;
  scanf("%d %d", &n, &q);
  for(i=1;i<=n;i++){
    scanf("%s",Que[i].name);
    scanf("%d",&Que[i].time);
  }
  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.time -= c;
    e += c;
    if(u.t > 0){
      enqueue(u);
    }
    else{
      printf("%s %d\n",u.name,e);
    }
  }
  return 0;
}