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

#define MAX 200000

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

P queue[MAX];
int head,tail;

void enqueue(P p){
  tail++;
  queue[tail] = p;
}

P dequeue(){
  P buf;
  buf = queue[head];
  head++;
  
  return buf;
}

int main(){
  int i, n, q, sum;
  P a;

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

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

  }
  
  return 0;
}

