#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NAME_LEN 10

typedef struct proc{
  char name[ NAME_LEN + 1 ];
  int time;
}Proc;

int main( void ){
  int n, q;
  scanf("%d %d\n", &n, &q);

  Proc *proc = ( Proc * )malloc( ( n + 1 )* sizeof( Proc ) );
  int head = 0, tail = n;

  for( int i = 0; i < n ; i ++ )
    scanf("%s %d\n", proc[ i ].name, &proc[ i ].time);

  int clock = 0;
  while( 1 ){
    if( head == tail ) break;

    Proc current = proc[ head ];
    current.time -= q;
    clock += q;

    head ++;
    head %= n + 1;

    if( current.time > 0 ){
      proc[ tail ] = current;
      tail ++;
      tail %= n + 1;
    } else {
      clock += current.time;
      printf("%s %d\n", current.name, clock);
    }
  }
  return 0;
}

