#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int n,q;
  int pro[100000];
  char name[100000][10];
  int i;
  int head;
  int tail;
  int time=0;

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

 
  

  for(i=0;i<n;i++) scanf("%s%d",name[i],&pro[i]);
  head=0;
  tail=n;
  while(head%(n+1)!=tail%(n+1)){
    if(pro[head%(n+1)]>q){
      pro[head%(n+1)]-=q;
      pro[tail%(n+1)]=pro[head%(n+1)];
      strcpy(name[tail%(n+1)],name[head%(n+1)]);
      head++;
      tail++;
      time+=q;
    }
    else{
      time+=pro[head%(n+1)];
      printf("%s %d\n",name[head%(n+1)],time);
      head++;
    }
  }
}
    
    

