#include<stdio.h>
#define MAX 100000
#define NAMELEN 10
typedef struct{
  char p[NAMELEN+1];
  int t;
}P;
P matcha[MAX];
int head=1,tail=1,n;

void enq(P u){
  matcha[tail]=u;
  tail++;
  if(tail==n+1) tail=0;
}
P deq(){
  P u;
  u=matcha[head];
  head++;
  if(head==n+1) head=0;
  return u;
}

int main(){
  int i,q,total=0;
  P u;
  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
     scanf("%s%d",u.p,&u.t);
     enq(u);
   }

  while(head!=tail){
    if(matcha[head].t<=q){
      u=deq();
      total+=u.t;
      printf("%s %d\n",u.p,total);
    }else{
      matcha[head].t-=q;
      u=deq();
      total+=q;
      enq(u);
    }
  }
  return 0;
}

