#include<stdio.h>
typedef struct{
  char name[10];
  int time;
}Process;
int main(){
  int i,q,takenTime,n,head,tail;
  Process pc[100001];

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

  head = 0;
  tail = n;
  takenTime = 0;

  while( head != tail ){
    if( pc[head].time - q > 0 ){
      takenTime += q;
      pc[head].time -= q;
      pc[tail] = pc[head];
      if( tail + 1 > n){
	tail = 0;
      }
      else {
	tail++;
      }
    }
    else{
      takenTime += pc[head].time;
      printf("%s %d\n",pc[head].name,takenTime);
    }

    if( head + 1 > n ){
      head = 0;
    }
    else {
      head++;
    }
  }
  return 0;
}
 