#include <stdio.h>
#include <string.h>

typedef struct kouzou{
  char name[100];

  int a;
} kouzou2;


kouzou2 Q[100005];
int head, tail,num;



void enqueue(kouzou2 t){

  Q[tail]=t;
  tail=(tail+1)%100005;

}




kouzou2 dequeue(){
  kouzou2 t = Q[head];
  head = (head+1)%100005;
  return t;
}


int min(int i,int j){return i<j?i:j;}


int main (){
  int elaps=0,c;
  int i,q;
  kouzou2 d;
  scanf("%d %d",&num,&q);
  for(i=1;i<=num;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].a);
  }
  head=1;
  tail=num+1;


  while(head!=tail){
    
    d=dequeue();
    c=min(q,d.a);
    d.a-=c;
    elaps+=c;
    
    if(d.a>0)enqueue(d);
    else{
      printf("%s %d\n",d.name,elaps);
    }
  }
  return 0;
}

