#include<stdio.h>

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


int main(){

  int n,q,i,head=0,tail,sum=0;
  struct data Q[100000];

  scanf("%d%d",&n,&q);

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

  tail = n;
  
  while(1){

    if(head == tail)break;
    
    if(Q[head].time<=q){
      sum = sum + Q[head].time;
      printf("%s %d\n",Q[head].name,sum);
      if(head == n)head = 0;
      else head++;
    }
    else{
      Q[head].time = Q[head].time - q;
      sum = sum + q;
      Q[tail] = Q[head];
      if(tail == n){
	tail = 0;
	head++;
      }
      else {
	tail++;
	if(head == n)head = 0;
	else head++;
      }
    }
  }
      
  return 0;
}