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

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

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

void enqueue(P x){
  strcpy( Q[tail].name,x.name);
  Q[tail].t=x.t;
  tail++;
}


int main(){
  int elaps = 0, c;
  int i, q,l=0;
  scanf("%d %d", &n, &q);
  tail=n+1;
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  i=1;
  while(1){

    if(Q[i].t>q){
      Q[i].t-=q;
      enqueue(Q[i]);
      elaps+=q;

    }

    else if(Q[i].t<=q){

      elaps+=Q[i].t;
      printf("%s %d\n",Q[i].name,elaps);
      l++;
      if(l==n)brea   }
    i++;

  }

  return 0;
}