#include<stdio.h>
#define N 100000
typedef struct{
  char s[10];
  int time;
  int process;
}data;
int main(){
  data a[N],b[N],c;
  int sum=0,t,d,i,j=0,head=0,tail;
  scanf("%d %d",&tail,&t);
  for(i=0;i<tail;i++){
    scanf("%s %d",a[i].s,&a[i].time);
    a[i].process=0;
  }
  while(head!=tail){
    if(a[head].time-t>=0){
      sum=sum + t;
      a[head].process=sum;
      a[head].time=a[head].time - t;    
    }
    else if(a[head].time-t<0){
      sum=sum + a[head].time;
      a[head].process=sum;
      a[head].time=0;
    }
    if(a[head].time==0){
      printf("%s %d\n",a[head].s,a[head].process);
      head++;
    }
    else{
      c=a[head];
      for(i=head;i<tail;i++){
	a[i]=a[i+1];
      }
      a[tail-1]=c;
    }	
  }
  return 0;
}
      

