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

#define LOOP_INIT 0
#define VER_INIT 0
#define P_NAME_MAX 11
#define P_NAME_INIT 0
#define QUEUE_MAX 100000
#define QUEUE_INIT 0
#define FIRST_ITEM 0
#define PROCESS_END 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 ];
		signed long slW_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_cnt = VER_INIT;
	unsigned long ulW_Cend_cnt = VER_INIT;
	unsigned long ulW_Dqueue_add_calc = VER_INIT;
	unsigned long ulW_Cqueue_loop_cnt = VER_INIT;

	struct st_process queue[ QUEUE_MAX ];
	struct st_process queue_buffer;

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

	INF_LOOP{
		if( ulW_Ddata_cnt == ulW_Cend_cnt ){
			break;
		}
		else{
			/* else?????????????????????????????\ */
		}
		queue[ FIRST_ITEM ].slW_Drem_time -= ulW_Dquantum;
		ulW_Dtotal_time += ulW_Dquantum;
		if( queue[ FIRST_ITEM ].slW_Drem_time <= PROCESS_END ){
			printf( "%s %d\n", queue[ ulW_Cinput_cnt ].ubW_Dp_name, ulW_Dtotal_time );
			ulW_Cend_cnt++;
			ulW_Dqueue_add_calc = ulW_Ddata_cnt - ulW_Cend_cnt;
			for( ulW_Cqueue_loop_cnt = LOOP_INIT; ulW_Cqueue_loop_cnt < ulW_Dqueue_add_calc; ulW_Cqueue_loop_cnt++ ){
				queue[ ulW_Cqueue_loop_cnt ] = queue[ NEXT_ITEM( ulW_Cqueue_loop_cnt ) ];
			}
		}
		else{
			queue_buffer = queue[ FIRST_ITEM ];
			ulW_Dqueue_add_calc = ulW_Ddata_cnt - ulW_Cend_cnt;
			for( ulW_Cqueue_loop_cnt = LOOP_INIT; ulW_Cqueue_loop_cnt < ulW_Dqueue_add_calc; ulW_Cqueue_loop_cnt++ ){
				queue[ ulW_Cqueue_loop_cnt ] = queue[ NEXT_ITEM( ulW_Cqueue_loop_cnt ) ];
			}
			queue[ ulW_Dqueue_add_calc ] = queue_buffer;
		}
	}
	return EXIT_SUCCESS;
}