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

#define MAX 2000000

typedef struct{
  char name[10];
  int t;
} Process;

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(Process);
Process dequeue(void);

int head,tail;

Process Q[MAX];

int main(int argc, char const *argv[]) {

  int n,q;
  int i;
  int sum_times = 0;
  Process Q1;

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

  for( i = 0 ; i < n ; i++ ){
    scanf("%s %d",Q[i].name,&Q[i].t);
  }

  initialize();

  tail = n;

  while( head != tail ){

    if( Q[head].t > q ){
      Q[head].t -= q;
      sum_times += q;
      enqueue(dequeue());
    }else{

      Q1 = dequeue();
      sum_times += Q1.t;
      printf("%s %d\n",Q1.name,sum_times);


    }


  }


  return 0;
}

void initialize(void){
  head = tail = 0;
}

int isEmpty(void){
  // empty??????1?????????
  if( head == tail )
    return 1;
  return 0;
}

int isFull(void){
  // full??????1?????????
  if( head == (tail+1)%MAX )
    return 1;
  return 0;
}

void enqueue(Process x){
  if( isFull() ){
    fprintf(stderr,"?????????????????????\n");
    exit(1);
  }

  Q[tail] = x;
  if( tail + 1 == MAX ){
    tail = 0;
  }else{
    tail++;
  }

}

Process dequeue(void){

  Process x;

  if( isEmpty() ){
    fprintf(stderr,"??¢??????????????????\n");
    exit(2);
  }

  x = Q[head];

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

  return x;

}