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

#define MAX 100000

typedef struct{
  char name[10];
  int time;
} data;

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(data);
data dequeue(void);

int head,tail,n;
data Q[MAX+1];

int main(){
  int q,i,t,sum=0;
  data d;

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

  initialize();

  tail=n;

  while(head!=tail){
    d=dequeue();

    if(d.time<=q){
      t=d.time;
    }else if(d.time>q){
      t=q;
    }
    d.time-=t;
    sum+=t;

    if(d.time<=0){
      printf("%s %d\n",d.name,sum);
    }else{
      enqueue(d);
    }
  }

  return 0;
}
  
    
void initialize(void){
  head=tail=0;
}

int isEmpty(void){
  if(head==tail){
    return 0; //empty
  }else{
    return 1;
  }
}

int isFull(void){
  if(head==((tail+1)%MAX)){
    return 1; //full
  }else{
    return 0;
  }
}

 void enqueue(data x){
  int full;

  full=isFull();
  if(full==1){
    fprintf(stderr,"overflow\n");
    exit(1);
  }

  Q[tail]=x;

  if(tail+1==MAX){
    tail=0;
  }else{
    tail++;
  }
}

data dequeue(void){
  int emp;
  data x;

  emp=isEmpty();
  if(emp==0){
    fprintf(stderr,"underflow\n");
    exit(8);
  }

  x=Q[head];

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

  return x;
}