#include <stdio.h>
#define N 100000

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

int head = 0, tail = 0, MAX;
process a[N];

void enqueue(process);
process dequeue(void);

int main(){
  int i, n, q, sum = 0; 
  process p;

  scanf("%d%d", &n, &q);
 
  for(i = 0;i < n;i++){
    scanf("%s%d", p.name, &p.time);
    enqueue(p);
  }
  while(1){
    if(head == tail) break;
    if(a[head].time > q){
      p = dequeue();
      p.time -= q;
      enqueue(p);
      sum += q;
    }
    else{
      p = dequeue();
      printf("%s %d\n", p.name, p.time + sum);
      sum += p.time;
    }
  }
  return 0;
}

void enqueue(process x){
  a[tail] = x;
  if(tail + 1 == N){
    tail = 0;
  }
  else tail++;
}

process dequeue(){
  process x;

  x = a[head];
  if(head + 1 == N){
    head = 0;
  }
  else head++;
  return x;
} 