#include<stdio.h>
#define LEN 100001

typedef struct p{
  char name[10];
  int t;
} Process;

Process que[LEN];
int head=1,tail=1;

void enqueue(Process P){
  if(head-tail != 1){
    que[tail] = P;
    tail = (tail+1)%LEN;
  }
}

Process dequeue(){
  if(head != tail){
    head= (head+1)%LEN;
    if(head == 0)return que[LEN-1];
    else return que[head-1];
  }
}

void Processing(int quantam){
  Process P;
  static int totaltime=0;
  
  P = dequeue();
  if(quantam >= P.t){
    totaltime += P.t;
    printf("%s %d\n",P.name, totaltime);
  }else{
    P.t -= quantam;
    totaltime += quantam;
    enqueue(P);
  }
}


int main(){
  Process buf;
  int quantam,i,n;
  
  scanf("%d %d",&n,&quantam);
  for(i=1; i<=n; i++){
    scanf("%s %d",buf.name, &buf.t);
    enqueue(buf);
  }
  while(head != tail){
    Processing(quantam);
  }

  return 0;
}


