#include<stdio.h>
#include<string.h>
int main(void){
  int n,q;
  int name[3000][20],t[3000];
  int top=0,tail=1;
  int i,j;
  int t_total=0;
  int count=0;

  scanf("%d",&n);
  scanf("%d",&q);
  tail=n;
  for(i=0;i<n;i++){
    scanf("%s",name[i]);
    scanf("%d",&t[i]);
  }
  while(top!=tail){
    if(t[top]<=q){
      t_total+=t[top];
      printf("%s %d\n",name[top],t_total);
      top=(top+1)%2000;
    }
    else{
      t_total+=q;
      strcpy(name[tail],name[top]);
      t[tail]=t[top]-q;
      top=(top+1)%2000;
      tail=(tail+1)%2000;
    }
  }
  return 0;
}