#include<stdio.h>
#include<string.h>
#define LEN 100005
typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=1, tail=0, n;
void eneque(P);
P deque(void);

void enque(P x){
  Q[tail]=x;
  if(tail+1==n)tail=0;
  else tail++; 
}

P deque(){
  P X;
  Q[head]=X;
  if(head+1==n)head=0;
  else head++;
  return X;
}


int main(){
  int elaps = 0;
  int i, q,k;
  P u;
  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  while(1){
    if(Q[head].t<=q){
      elaps=elaps + Q[head].t;
      printf("%s %d\n",Q[head].name,elaps);
      k++;
      if(k==n)break;
    }
    else{ 
      Q[head].t = Q[head].t - q;
      elaps = elaps + q;
      enque(Q[head]);
      deque();
    }
    
    return 0;
  }
}