#include<stdio.h>
 
typedef struct {
  char name[100];
  int t;
}Hirasawa;
 
int main(void){
  int i,q,n,count;
  int zi=0,atama=0,shipo=0;
  Hirasawa x,Q[1000000];
  scanf("%d %d", &n, &q);
   
  for ( i = 0; i < n; i++){
    scanf("%s", x.name);
    scanf("%d", &x.t);
    Q[atama]=x;
    atama++;
  }
   
  while(1){
    shipo++;
    x=Q[shipo-1];
    if(x.t<=q){
      zi+=x.t;
      printf("%s %d\n", x.name, zi);
    }
    else{
      x.t-=q;
      zi+=q;
      Q[atama]=x;
      atama++; 
    }
    if(atama-shipo==0)break;
  }
  return 0;
}