#include<stdio.h>

int Q[1000000],head=0,tail=0;

void enqueue(int x){
  Q[tail]=x;
  tail++;
}

int dequeue(){
  int x;
  x= Q[head];
  head++;
  
  return x;
}


  
  

int main() {


  int x,i,j,n,q,sum_time=0;

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

  char c[n][10];
  int time[n];

  

  for(i=0;i<n;i++){
    scanf("%s%d",c[i],&time[i]);
    enqueue(i);
  }

  while(head!=tail){
    x=dequeue();
    if(q<time[x]){
      sum_time+=q;
      time[x] = time[x]-q;
      enqueue(x);
    }
    else{
      sum_time+=time[x];
      printf("%s %d\n",c[x],sum_time);
    }
  }

  return 0;
}
    
    
  
  
  

