#include <stdio.h>
#define L 100005
#define MAX 100002
typedef struct{
  char name[100];
  int time;
}Pro;

Pro Q[L];
int head,tail,tail,n;

void initialize(void);
Pro enq(Pro);
Pro deq(void);
int isEmpty(void);
int isFull(void);
int min(int,int);


int main(){
  int el=0,b,i,q;
  Pro a;
  initialize();
  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }
  head=1;
  tail=n+1;

  while(1){
    if(head==tail)break;
    a=deq();
    b=min(q, a.time);
    a.time -= b;
    el     += b;
    if( a.time > 0 )
      enq(a);
    else 
      printf("%s %d\n", a.name, el);
  }
  
  return 0;

}

void  initialize (){
  head= tail=0;
}
int isEmpty(){
  return head == tail;
}
int isFull(){
  return head == (tail+1)%MAX;
}
Pro enq(Pro x){
  if(isFull())
    printf("error!\n");
  Q[tail]=x;
  tail=(tail+1)%L;
  return x;
}
Pro deq(){
  Pro x;
  if(isEmpty())
    printf("error\n");
  x=Q[head];
  head=(head+1)%L;
  return x;
}
int min(int a,int b){
  if(a<b)return a;
  return b;
}
  
