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

typedef struct FIFO{
  char name[100];
  int time;
} Q;


void add(Q);
Q get();
int change(int,int);

Q IN[N];
int head,tail,count;


int main(){

  int i,n,record,alltime=0;
  Q h;

  scanf("%d %d",&count,&n);
  for(i=1;i<=count;i++){
    scanf("%s %d",IN[i].name,&IN[i].time);
  }
  head=1;
  tail=count+1;
  
  while(head!=tail){
    h = get();
    record = change(n,h.time);
    h.time -= record;
    alltime += record;
    if(h.time>0) add(h);
    else {
      printf("%s %d\n",h.name,alltime);
    }
  }
  return 0;
}

void add(Q x){
  IN[tail] = x;
  tail = (tail +1)%N;
}

Q get(){
  Q x = IN[head];
  head = (head + 1)%N;
  return x;
}

int change(int a,int b){
  if(a<b) return a;
  else return b;
}

