#include<stdio.h>
#include<string.h>
#define N 100001
typedef struct Process{
  int time;
  char name[10];
} proc;
int main(){
  int i,n,takenTime,head,tail,q;
  proc pc[N];
  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 ){
      pc[tail].time = pc[head].time - q;
      strcpy(pc[tail].name,pc[head].name);
      takenTime += q;
      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;
}