#include<stdio.h>

int main(){

  typedef struct{

    char pname[10];
    int rtime;
  }process;


  process inprocess[100000];

  int i,sum,runtime,flag =0;
  int sumtime;


  scanf("%d%d",&sum,&runtime);

  for(i = 0; i < sum; i++){ /*input process information*/

    scanf("%s%d",inprocess[i].pname,&inprocess[i].rtime);

  }

  i = 0;

  while(flag != sum){

    if(i > sum - 1){

      i = 0;
    }

    if(inprocess[i].rtime > 0){

      if(inprocess[i].rtime > runtime){

	inprocess[i].rtime = inprocess[i].rtime - runtime;

	sumtime = sumtime + runtime;

      }

      else if(inprocess[i].rtime <= runtime){

	sumtime = sumtime + inprocess[i].rtime;

	inprocess[i].rtime = 0;  

	printf("%s %d\n",inprocess[i].pname,sumtime);

	flag = flag + 1;

      }

      i = i + 1;

    }

    else if(inprocess[i].rtime <= 0){

      i = i +1;

    }

  }

  return 0;

}