#include<stdio.h>
#include<string.h>
#define N 100000

int main(void){
  int ms = 0;
  int c=0;
  int n, q, i, j=0;
  char Pname[N][10]; // ??\?????¨
  int Ptime[N]; // ??\?????¨
  char pn[N][10]; // ????????¨
  int pt[N]; // ????????¨

  char t1[10]; // ????????¨
  int t2; // ????????¨

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

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

  c = n;

  for(i=0;i<n;i++){
    printf("%s %d\n",Pname[i], Ptime[i]);
  }

  while(1){

    if(c==0){ break;}

    if(Ptime[0] > q){

      strcpy(t1, Pname[0]);
      t2=Ptime[0] - q;

      for(i=1;i<c;i++){
        strcpy(Pname[i-1], Pname[i]);
        Ptime[i-1] = Ptime[i];
      }

      strcpy(Pname[c-1], t1);
      Ptime[c-1]=t2;
      ms += q;
    }

    if(Ptime[0] <= q){
      ms += Ptime[0];
      strcpy(t1, Pname[0]);
      t2 = Ptime[0];

      printf("%s %d\n", Pname[0], ms);

      for(i=1;i<c;i++){
        strcpy(Pname[i-1], Pname[i]);
        Ptime[i-1] = Ptime[i];
      }

      j++;
      c = c-1;

    }
  }

  return 0;

}