#include<stdio.h>
#include<stdlib.h>
#define N 1000002

typedef struct{
  char name[11];
  int time;
}Record;

Record A[N];
int head=0,tail,n;
void enqueue(Record);
Record dequeue(void);

void enqueue(Record x){
  if(head == (tail + 1) % N){
    printf("error %d\n",tail);
    exit(1);
  }
  A[tail] = x;
  if(tail + 1 == N){
    tail = 0;
  }else{
    tail++;
  }
}

Record dequeue(){
  if(head == tail){
    printf("error2\n");
    exit(1);
  }
  Record x = A[head];
  if(head + 1 ==  N){
    head == 0;
  }else{
    head++;
  }
  return x;

}

int main(){
  int i,q,t=0,s;
  Record B;
  scanf("%d %d",&n,&q);

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

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

  return 0;
}

