#include <stdio.h>
#include <string.h>

#define LOOP_INIT 0
#define VER_INIT 0
#define P_NAME_MAX 10
#define P_NAME_INIT 0
#define QUEUE_MAX 100000
#define QUEUE_INIT 0
#define FIRST_ITEM 0
#define PROCESS_END -1
#define STACK_MAX 1000
#define TRUE 1
#define FALSE 0
#define EXIT_SUCCESS 0;
#define INF_LOOP while( 1 )
#define NEXT_ITEM( x ) ( ( x ) + 1 )

int main( void )
{
	struct st_process {
		unsigned char ubW_Dp_name[ P_NAME_MAX ];
		unsigned long ulW_Drem_time;
	};

	unsigned long ulW_Ddata_cnt = VER_INIT;
	unsigned long ulW_Dquantum = VER_INIT;
	unsigned long ulW_Dtotal_time = VER_INIT;
	unsigned long ulW_Cinput_loop_cnt = VER_INIT;
	unsigned long ulW_Cloop_cnt = VER_INIT;
	unsigned long ulW_Cend_cnt = VER_INIT;
	unsigned long ulW_Cstack_cnt = VER_INIT;
	unsigned long ulW_Dqueue_add_calc = VER_INIT;
	unsigned long ulW_Cqueue_loop_cnt = VER_INIT;
	unsigned char ubW_Fqueue_flag = VER_INIT;

	struct st_process queue[ QUEUE_MAX ];
	struct st_process process_stack[ STACK_MAX ];

	scanf( "%d %d", &ulW_Ddata_cnt, &ulW_Dquantum );
	for( ulW_Cinput_loop_cnt = LOOP_INIT; ulW_Cinput_loop_cnt < ulW_Ddata_cnt; ulW_Cinput_loop_cnt++ ){
		scanf( "%s", queue[ ulW_Cinput_cnt ].ubW_Dp_name );
		scanf( "%d", &queue[ ulW_Cinput_cnt ].ulW_Drem_time );
	}

	for( ulW_Cloop_cnt = LOOP_INIT; ulW_Cloop_cnt < ulW_Ddata_cnt + ulW_Cend_cnt; ulW_Cloop_cnt++ ){
		ubW_Fqueue_flag = FALSE;
		if( queue[ ulW_Cloop_cnt ].ulW_Drem_time <= ulW_Dquantum ){
			ulW_Dtotal_time += queue[ ulW_Cloop_cnt ].ulW_Drem_time;
			queue[ ulW_Cloop_cnt ].ulW_Drem_time = ulW_Dtotal_time;
			ubW_Fqueue_flag = TRUE;
		}
		else{
			ulW_Dtotal_time += ulW_Dquantum;
			queue[ ulW_Ddata_cnt + ulW_Cend_cnt ].ulW_Drem_time = queue[ ulW_Cloop_cnt ].ulW_Drem_time - ulW_Dquantum;
			strcpy( queue[ ulW_Ddata_cnt + ulW_Cend_cnt ].ubW_Dp_name, queue[ ulW_Cloop_cnt ].ubW_Dp_name );
			ulW_Cend_cnt++;
		}
		if( ubW_Fqueue_flag == FALSE ){
			queue[ ulW_Cloop_cnt ].ulW_Drem_time = PROCESS_END;
		}
		process_stack[ ulW_Cstack_cnt ] = queue[ ulW_Cloop_cnt ];
		if( process_stack[ ulW_Cstack_cnt ].ulW_Drem_time != PROCESS_END ){
			printf( "%s %d\n", process_stack[ NEXT_ITEM( ulW_Cstack_cnt ) ].ubW_Dp_name, process_stack[ NEXT_ITEM( ulW_Cstack_cnt ) ].ulW_Drem_time );
		}
		else{
		}
	}
	return EXIT_SUCCESS;
}