#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100000

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

}Data;

typedef struct{
  Data data[N];
  int head;
  int tail;

}Pro;

void in(int *, Pro *, char *, int);
Data out(int *, Pro *);

int main(){

  int i;
  int n, q;
  char name[10], time[5];
  Pro queue;
  Data tmp;
  int time_sum = 0;

  scanf("%d%d", &n, &q);

  queue.head = 0;
  queue.tail = 0;
  for(i = 0; i < n; i++){
    queue.data[i].name[0] = ' ';
  }

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

  for(tmp = out(&n, &queue); tmp.name[0] != ' '; tmp = out(&n, &queue)){

    if(tmp.time - q > 0){
      in(&n, &queue, &tmp.name[0], tmp.time - q);
      time_sum += q;
    }
    else {
      time_sum += tmp.time;
      printf("%s %d\n", tmp.name, time_sum);
    }    

  }

  return 0;
}

void in(int *n, Pro *queue, char *name, int time){

  strcpy(queue->data[queue->tail].name, name);
  queue->data[queue->tail].time = time;

  if(queue->tail < *n - 1) queue->tail++;
  else queue->tail = 0;

}

Data out(int *n, Pro *queue){

  Data tmp;

  tmp = queue->data[queue->head];
  queue->data[queue->head].name[0] = ' ';

  if(queue->head < *n - 1) queue->head++;
  else queue->head = 0;

  return tmp;
}