#include<stdio.h>
#include<string.h>
#define LEN 100005

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

P Q[LEN+1];
int head, tail, n;

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


P dequeue(){
  int l;
  l=head;
  head=head+1;
  head=head%(LEN+1);
}


int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;

  head=1;
  tail=n+1;

  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  whil(0){
    if(head==tail) break;
    u=dequeue();
    if(u.t>q){
      c=c+q;
      u.t=u.t-q;
      enqueue(u);
    } else{
      c=c+u.t;
      printf("%s %d\n",u.name,c);
    }
  }
  
  return 0;
}