#include<stdio.h>
#include<stdlib.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,P y){
  int i;
  P a;
  a=x;
  x=y;
  y=a;

}

P dequeue(elaps){
  int i;
  P a;
  for(i=0;i<n-elaps;i++){
    a=Q[i];
    Q[i]=Q[i+1];
    Q[i+1]=a;
  }
  return a;
}


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

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  while(elaps!=n){
    c++;
  Q[0].t=Q[0].t-q;
  if(Q[0].t<q){
    elaps++;
    u=dequeue(elaps);
    printf("%s %d\n",u.name,u.t);
  }
  for(i=0;i<n-1-elaps;i++){
    enqueue(Q[i],Q[i+1]);
  }
  }
  return 0;
}

