#include <stdio.h>
typedef struct{
  char name[10];
  int time;
}Rrobin;

Rrobin dequeue(void);
void enqueue(Rrobin);


int head, tail, n;
Rrobin queue[100000];

int main(){

  int q, i, count=0, total=0;
  Rrobin a;

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

  for(i=0; i<n; i++){
    scanf("%s %d", queue[i].name, &queue[i].time);
  }
  head=0; tail=n-1;

  //ok from here

  while(total!=n){
    
    a=dequeue();//先頭を取り出してaに入れる

    if(a.time==0){
      //  enqueue(a);
      continue;
    }
    if(a.time<=q){

      count+=a.time;
      a.time=0;
      //      enqueue(a);
      printf("%s %d\n", a.name, count);
      total++;
    }  
    if(a.time>q){//100より大きい
     
      count+=q;
      a.time-=q;
      enqueue(a);

    }
    
  }
  return 0;
    
}


Rrobin dequeue(void){

  Rrobin b;
  b=queue[head];
  head=(head+1)%n;
  
  return b;
}

void enqueue(Rrobin a){

  tail=(tail+1)%n;
  queue[tail]=a;
}

