#include <stdio.h>
#include <string.h>
#define n_max 100005
#define len 100

typedef struct task{
  char name[len];
  int time;
}T;

int main(){
  int fin=0,i,q,n,count=0;
  T Q[n_max];

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

  i=1;
  count=n;

  while(1){
    if(Q[i].time<=q &&  Q[i].time!=0){
      count--;
      fin+=Q[i].time;
      printf("%s %d\n",Q[i].name,fin);
      if(count==0)break;
    }
    else{
      fin+=q;
      Q[i].time-=q;
      Q[i+count].time=Q[i].time;
      strcpy(Q[i+count].name,Q[i].name);
    }
    i++;
  }
  return 0;
}

