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

void enqueue(int index);
int dequeue(void);

int Q[1001];
int lastQ = 0;

char name[1001][11];
int time[1001];

main(){

  int i, index, n, q, elapsedTime = 0;

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

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

  while(n!=0){

    index = dequeue();
    time[index] -= q;
    elapsedTime += q;

    if(time[index] <= 0){
      elapsedTime += time[index];
      printf("%s %d\n",name[index],elapsedTime);
      n--;
    }else{
      enqueue(index);
    }

  }

  return 0;

}

void enqueue(int index){
  Q[lastQ++] = index;
}

int dequeue(void){

  int i,tmp = Q[0],len;

  for(i=0, len=--lastQ; i<lastQ; i++)
    Q[i] = Q[i+1];

  return tmp;

}