#include <stdio.h>

typedef struct{
  char name[10];
  int t;
  int flag;
} Process;

int main(int argc, char const *argv[]) {

  int num,times,i;
  Process Q[100000];
  int count = 0, sum = 0;

  scanf("%d%d",&num,&times);

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


  while( count != num ){

    for( i = 0 ; i < num ; i++ ){
      Q[i].t -= times;
      if( Q[i].t > 0 ){
        sum += times;
      }
      if( Q[i].t < 0 && Q[i].flag == 1 ){
        sum += times+Q[i].t;
        Q[i].flag = 0;

        if( num == 1 ){
          printf("%s %d\n",Q[i].name,sum);
          return 0;
        }


        if( count+1 == num ){
          sum += times;
        }

        count++;

        printf("%s %d\n",Q[i].name,sum);

      }

    }

  }

  return 0;
}