#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[MAX];
int head, tail, n;

void initailize(){
  head = 0; tail = 0;
}

void enqueue(P x){
  Q[tail]=x;
  tail = (tail+1)%MAX;
}

P dequeue(){
  P x = Q[head];
  head = (head+1)%MAX;
  return x;
}


int main(void){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for (i=1 ; i<=n ; i++){
    P u1;
    scanf("%s %d", u1.name, &u1.t);
    enqueue(u1);
  }

  while(head!=tail){
    u=dequeue();
    if(u.t > q){
      elaps += q;
      u.t -= q;
      enqueue(u);

    }
    else{
      elaps += u.t;
      printf("%s %d\n",u.name, elaps);
    }
  }
  return 0;
}
