#include<stdio.h>
#include<string.h>
#define M 1000000

typedef struct{
  int t;
  char n[10];
}qu;

qu Q[M];
int H,T;

void en(qu q){
  Q[T] = q;
  T++;
}

qu de(){
  qu q;

  q = Q[H];
  H++;
  return q;
}

int main(){
  int i,n,cnt,sum;
  qu q;

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

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

  sum = 0;
  H = 0;
  T = n;

  while(H != T){
    q = de();

    if(q.t <= cnt){
      sum += q.t;
      printf("%s %d\n",q.n,sum);
    }
    else {
      q.t -= cnt;
      en(q);
      sum += cnt;
    }
  }

  return 0;
}

