#include<stdio.h>
#include<string.h>
#define N 100000

typedef struct{
  int time;
  char name[10];
}Process;

int main(){
  Process Pro[N],take;
  int i,loop,quan;
  int first=0,last;
  int sum=0;
  
  scanf("%d %d",&loop,&quan);
  last=loop;
  for(i=0;i<loop;i++){
    scanf("%s %d",Pro[i].name,&Pro[i].time);
  }
  
  while(first!=last){
    take=Pro[first++];
    if(take.time>quan){
      Pro[last].time=take.time-quan;
      strcpy(Pro[last].name,take.name);
      last++;
      sum+=quan;
    }
    
    else if(take.time<=quan){
      sum+=take.time;
      printf("%s %d\n",take.name,sum);
    }
  }
  
  return 0;
}

