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

#define N 100000

typedef struct que{
  char name[10];
  int num;
}que;

int main(void){
  int n,i,q,sum=0,count=0;
  que *Q;

  scanf("%d %d",&n,&q);
  if(n>N||n<=0) exit(1);

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

  while(count!=n){
    for(i=0;i<n;i++){
      if(Q[i].num<=q && Q[i].num!=0){
	sum+=Q[i].num;
	Q[i].num-=Q[i].num;
	printf("%s ",Q[i].name);
	printf("%d\n",sum);
	count++;
      }
      else if (Q[i].num==0) continue;

      else {
	Q[i].num-=q;
	sum+=q;
      }
    }

  }

  free(Q);
  
  return 0;
}