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

void enqueue(int, int);
int dequeue(void);

int Q[10000][2];
int firstQ, lastQ;

char name[10000][11];

main(){

  int i, index;
  char inName[11];
  int inTime;
  int elapsedTime = 0;
  int n,q;

  firstQ = 0;
  lastQ = 0;

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

  for(index=0; index<n; index++){
    scanf("%s %d",inName,&inTime);
    strcpy(name[index],inName);
    enqueue(index,inTime);
  }

  while(n!=0){

    Q[firstQ][1] -= q;
    elapsedTime += q;

    if(Q[firstQ][1] <= 0){

      elapsedTime += Q[firstQ][1];
      printf("%s %d\n",name[Q[firstQ][0]],elapsedTime);
      n--;

    }else{

      enqueue(Q[firstQ][0],Q[firstQ][1]);

    }

    dequeue();

  }

  return 0;

}

void enqueue(int index, int inTime){

  Q[lastQ][0] = index;
  Q[lastQ][1] = inTime;

  lastQ++;

}

int dequeue(void){

  return Q[firstQ++][1];

}