#include <stdio.h>

#define MAX 100000

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

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

int head = 0;
int tail = 0;
process Q[MAX];

int main(){
  int i, n, q, total=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(Q[head].time > q){
      p = dequeue();
      p.time -= q;
      enqueue(p);
      total += q;
    }else{
      p = dequeue();
      printf("%s %d\n", p.name, p.time + total);
      total += p.time;
    }
  }     

  return 0;
 
}

void enqueue(process p){
  Q[tail] = p;
  if(tail+1 == MAX){
    tail = 0;
  }else{
  tail++;
  }
}

process dequeue(){
  process x;

  x = Q[head];

  if(head+1 == MAX){
    head = 0;
  }else{
    head++;
  }
  return x;
}