#include<stdio.h>
#include<string.h>
#define LENGHTH 100010
typedef struct p{

  char pname[100];
  int runtime;

}process;

process runprocess[LENGHTH];

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

int head = 0;
int tail = 0;


int main(){

  int sumprocess,rtime,sumruntime = 0;
  int i,j;
  process data;

  scanf("%d%d",&sumprocess,&rtime);

  for(i = 0; i < sumprocess; i++){

    scanf("%s%d",runprocess[i].pname,&runprocess[i].runtime);

  }

  head = 0;
  tail = sumprocess; /*????????°??????*/

  while(head != tail){

    data = dequeue();

    // data.runtime = data.runtime - rtime;                                                                                                                                                                                                                                                                                                                          

    if(data.runtime - rtime > 0){

      enqueue(data,data.runtime - rtime);


      sumruntime = sumruntime + rtime;

    }

    else{

      sumruntime = sumruntime + data.runtime;

      printf("%s %d\n",data.pname,sumruntime);

    }

  }

  return 0;

}


void enqueue(process data, int stime){

  strcpy(runprocess[tail].pname,data.pname);
  runprocess[tail].runtime = stime;

  tail = tail + 1;

  if(tail >= LENGHTH){

    tail = 0;

  }

}

process dequeue(){

  int phead;

  phead = head;

  head = head + 1;

  if(head >= LENGHTH){

    head = 0;

  }

  return runprocess[phead];

}