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

#define QUEUE_MAX 100005														/* ?????????????????\????????§???										*/
#define NAME_MAX 100															/* ????????????????????§???											*/
#define HEAD_INIT 1																/* ?????\???????????????????????????									*/
#define PROCESS_END 0															/* ?????????????????????											*/
#define HEAD_END 1																/* ?????\???????????????											*/
#define TAIL_END 1																/* ?????\????°??????????											*/
#define VER_INIT 0																/* ?????°?????????												*/
#define LOOP_INIT 1																/* ??????????????????????????????										*/
#define EXIT_SUCCESS 0															/* ??£?????????????????????											*/
#define NEXT_ITEM( x ) ( ( x ) + 1 )											/* ?¬????????´?													*/

static signed long judge_min( 													/* 2??????????´?????????????????°????????????????????????¢??°					*/
signed long slW_Ddata_first, 													/* ??????????±???????1											*/
signed long slW_Ddata_second );													/* ??????????±???????2											*/
static void enqueue( 															/* ?????\????°?????????¢??°											*/
Process st_queue_add );															/* ??????????±??????\????????¢?????¬???									*/
static Process dequeue( void );													/* ?????\??????????????¢??°											*/

typedef struct {
	unsigned char aubG_Dp_name[ NAME_MAX ];										/* ???????????????												*/
	signed long slG_Drem_time;													/* ????????????????????????											*/
} Process;																		/* ?????????????§???????											*/

Process st_queue[ NEXT_ITEM( QUEUE_MAX ) ];										/* ?????????????????\???											*/

unsigned long ulG_Dqueue_head = HEAD_INIT;										/* ?????\??????????????????											*/
unsigned long ulG_Dqueue_tail;													/* ?????\????°?????????????											*/
unsigned long ulG_Ddata_cnt;													/* ??????????????°?¨???¶?????°										*/

int main( void )
{
	unsigned long ulW_Dtotal_time = VER_INIT;									/* ??????????¨????????¨???¶?????°										*/
	signed long slW_Dcalc;														/* ????\???¨?????°												*/
	unsigned long ulW_Cloop_cnt;												/* ?????????????????????											*/
	unsigned long ulW_Dquantum;													/* ???????????????????????¨?????°										*/
	Process st_queue_calc;														/* ????\???¨?§???????												*/

	scanf( "%d %d", &ulG_Ddata_cnt, &ulW_Dquantum );							/* ??????????????°??¨????????????????????\???								*/
	/* ???????????\?????¨????????? */
	for( ulW_Cloop_cnt = LOOP_INIT; ulW_Cloop_cnt <= ulG_Ddata_cnt; ulW_Cloop_cnt++ ){
		/* ?????????????????¨?????????????????????????????\??? */
		scanf( "%s %d", st_queue[ ulW_Cloop_cnt ].aubG_Dp_name, &st_queue[ ulW_Cloop_cnt ].slG_Drem_time );
	}/* ???????????\?????¨?????????????????? */

	ulG_Dqueue_tail = NEXT_ITEM( ulG_Ddata_cnt );								/* ?????\????°?????????????????????????									*/
	/* ?????\????????¨?????\????°????????????§????????????????????? */
	while( ulG_Dqueue_head != ulG_Dqueue_tail ){
		st_queue_calc = dequeue();												/* ????\???¨?§???????????????\??????????????¢??°?????????????????£??\				*/
		/* ????\???¨?????°???????????????????????¨????\???¨?§????????????????????????????????°??????????????????£??\ */
		slW_Dcalc = judge_min( ulW_Dquantum, st_queue_calc.slG_Drem_time );
		st_queue_calc.slG_Drem_time -= slW_Dcalc;								/* ????\???¨?§????????????????????????????????\???¨?????°?????????				*/
		ulW_Dtotal_time += slW_Dcalc;											/* ??????????¨??????????????\???¨?????°?????????							*/
		/* ????\???¨?§????????????????????????????????????????????????§????????´??? */
		if( st_queue_calc.slG_Drem_time > PROCESS_END ){
			enqueue( st_queue_calc );											/* ?????\????°?????????¢??°???????\???¨?§???????????????????					*/
		}
		else{
			printf( "%s %d\n", st_queue_calc.aubG_Dp_name, ulW_Dtotal_time );	/* ?????????????????????????????¨????¨????????????????						*/
		}
	}/* ?????\????????¨?????\????°????????????§?????????????????????????????? */
	return EXIT_SUCCESS;
}

static signed long judge_min( 													/* 2??????????´?????????????????°????????????????????????¢??°					*/
signed long slW_Ddata_first, 													/* ??????????±???????1											*/
signed long slW_Ddata_second )													/* ??????????±???????2											*/
{
	/* ??????????±???????1????????????????±???????2???????°?????????´??? */
	if( slW_Ddata_first < slW_Ddata_second ){
		return slW_Ddata_first;													/* ??????????±???????1?????????										*/
	}
	else{
		return slW_Ddata_second;												/* ??????????±???????2?????????										*/
	}
}

static void enqueue( 															/* ?????\????°?????????¢??°											*/
Process st_queue_add )															/* ??????????±??????\????????¢?????¬???*/
{
	st_queue[ ulG_Dqueue_tail ] = st_queue_add;									/* ?????????????????\?????????????????????????´?????????????????±??????\????????£??\	*/
	/* ?????\????°????????????????????????????????????\????????§????????´??? */
	if( ulG_Dqueue_tail == QUEUE_MAX ){
		ulG_Dqueue_tail = TAIL_END;												/* ?????\????°?????????????????????????????????´							*/
	}
	else{
		ulG_Dqueue_tail++;														/* ?????\????°?????????????????????????????????????							*/
	}
}

static Process dequeue( void )													/* ?????\??????????????¢??°											*/
{
	Process st_queue_calc;														/* ????\???¨?§???????												*/

	st_queue_calc = st_queue[ ulG_Dqueue_head ];								/* ????\???¨?§???????????????\????????????????´??????????						*/
	/* ?????\??????????????????????????????????????\????????§????????´??? */
	if( ulG_Dqueue_head == QUEUE_MAX ){
		ulG_Dqueue_head = HEAD_END;												/* ?????\??????????????????????????????????????´							*/
	}
	else{
		ulG_Dqueue_head++;														/* ?????\??????????????????????????????????????????							*/
	}
	return st_queue_calc;														/* ????\???¨?§????????????????										*/
}