#include <stdio.h>

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

int n;
int head=0, tail=0;
process p[100000];

void enqueue(process x){
  if(tail == n) tail = 0;
  p[tail++] = x;
}

process dequeue(){
  if(head == n) head = 0;
  return p[head++];
}

int main(){
  int q, i, timer=0, flag=0;
  scanf("%d%d", &n, &q);
  for(i=0; i<n; i++) scanf("%s%d", p[i].name, &p[i].time);
  while(flag != n){
    process x;
    x = dequeue();
    if(x.time <= q){
      flag++;
      timer += x.time;
      printf("%s %d\n", x.name, timer);
    }else{
      timer += q;
      x.time -= q;
      enqueue(x);
    }
  }
  return 0;
}