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

#define MAX 100000

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


void enqueue(process);
process dequeue(void);
int isEmpty(void);
int isfull(void);

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

int main(){
  process input, processing;
  int n, q, x, y;
  int i, time = 0;

  scanf("%d%d", &n, &q);
  
  for(i = 0; i < n; i++){
    scanf("%s %d", input.name, &input.time);
    enqueue(input);
  }

  while(1){
    if(isEmpty() == 1)break;
    
    processing = dequeue();
    
    if(processing.time <= q){
      time += processing.time;
      printf("%s %d\n", processing.name, time);
    }
    
    else{
      processing.time -= q;
      time += q;
      enqueue(processing);
    }
  }
  

  return 0;
}


int isEmpty(){
  int sta = 0;

  if(head == tail) sta = 1;

  return sta;
}

int isFull(){
  int sta = 0;

  if(head == (tail + 1) % MAX) sta = 1;

  return sta;
}

void enqueue(process x){
  if(isFull() == 1) exit(1);

  Q[tail] = x;

  if(tail + 1 == MAX) tail = 0;

  else tail++;
}

process dequeue(){
  process x;
  
  if(isEmpty() == 1) exit(2);

  x = Q[head];

  if(head + 1 == MAX) head = 0;

  else head++;

  return x;
}

