#include <stdio.h>
#define N 200000
 
typedef struct {
  int time;
  char name[20];
} node;
 
node queue[N];
int start = 0;
int end = 0;
 
void enqueue( node x )
{
  queue[end++] = x;
  if ( end == N )
    end = 0;
}
 
node dequeue()
{
  int tmp = start++;
  if ( start == N )
    start = 0;
  return queue[tmp];
}
 
int emptyp()
{
  return start == end;
}
 
int main( void )
{
  int n, q, i;
  scanf( "%d", &n );
  scanf( "%d", &q );
 
  node a;
  for ( i = 0; i < n; i++ ) {
    scanf( "%s", a.name );
    scanf( "%d", &a.time );
    enqueue( a );
  }
 
  int time = 0;
 
  while( !emptyp() ) {
    a = dequeue();
    if ( a.time > q ) {
      a.time -= q;
      time += q;
      enqueue( a );
    } else {
      time += a.time;
      printf( "%s %d\n", a.name, time );
    }
  }
 
  return 0;
}
