#include<stdio.h>
#include<string.h>
#define SIZE 100000

typedef struct pp{
  char name[100];
  int t;
} P;

P Q[SIZE];
int head,tail,n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%SIZE;
}

P dequeue(){
  P x;
  x=Q[head];
  head=(head+1)%SIZE;

  return x;

}

int min(int a,int b){
  if(a>b){
    return b;
  }
  else{
    return a;
  }
}

int main(){
  int time=0;
  int c,i,q;
  P p;

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

  for(i=1;i<n+1;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  head=1;
  tail=n+1;

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

  return 0;
}
      
  

