

  
#include<stdio.h>
#include<stdlib.h>

#define MAX 10000

struct a{
  
  char name[10];
  int time;  

};

void initialize(void);
int isEmpty();
int isFull();
void enqueue(struct a);
struct a dequeue();

int head,tail;
struct a p[MAX],x;


int main( ){

  int n,q,i,count=0;

  initialize();

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

  tail=n;
 
  // printf("%d",tail);
  
  
  for(i=0;i<n;i++){

    scanf("%s %d",p[i].name,&p[i].time);
    
  }

  //printf("wa-i1\n");
  
  while(1){

    // printf("wa-i\n");
    
    if(p[head].time-q<=0){

      // printf("wa-i3\n");
      
      count+=p[head].time;
      x=dequeue();
      printf("%s %d\n",x.name,count);
      if(isEmpty()==1) break;
    }
    else{

      // printf("wa-i4\n");
      count+=q;
      p[head].time=p[head].time-q;
      //printf("wa-i5\n");
      x = dequeue();
      //printf("wa-i6\n");
      enqueue(x);
    }

  }
  
  return 0;
}

void initialize(){

  head = tail = 0;

}

int isEmpty(){

  if(head == tail) return 1;
  else return 0;

}

int isFull(){

  if(head==(tail+1)%MAX) return 1;
  else return 0;

}

void enqueue(struct a x){

  if(isFull()==1){
    printf("?????????????????????\n");
    exit(1);
  }

  p[tail]=x;
  if(tail+1==MAX) tail = 0;
  else tail++;

}

struct a dequeue(){

  struct a x;

  if(isEmpty()==1){
    printf("??¢??????????????????\n");
    exit(2);
  }
    
  x=p[head];

  if(head+1==MAX) head=0;
  else head++;

  return x;

}
  




    