#include<stdio.h>

#define MAX 100000

struct process{
  char name[10];
  int time;
};

int main(){
  int n,q,i,j,t,b,buf;
  struct process p[MAX];

  t = 0;
  
  scanf("%d %d",&n,&q);
  for(i = 0;i < n; i++)
    scanf("%s %d",p[i].name,&p[i].time);

  i = 0;
  while(1){
    
    if(p[i].time <= q){
      t += p[i].time;
      printf("%s %d\n",p[i].name,t);
      if(i == n - 1)
	break;
      i++;

    }
    
    else {
      t = t + q;
      buf = ++n;
      b = q;
      for(j = 0;;j++){
	if(p[i].name[j] == EOF) break;
	p[n - 1].name[j] = p[i].name[j];
      }
      q = b;
      n = buf;
      p[n - 1].time = p[i].time - q;
      i++;
    }
  }
  
  return 0;
}

