#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>

#define DT_MAX (100000)

typedef struct aaa{
	char	name[12];
	short	tm;
	short	fst_tm;
	short   dsp_tm;
	struct aaa *next_p;
} TBL_T;

TBL_T	*top_p;
TBL_T   *cmpl_p;

/**------------ SUB ROUTIONE -------------*/
void func_chain(TBL_T *wk_p,TBL_T **top_p)
{
	TBL_T *wk2_p;

	wk2_p = *top_p;

	if (wk2_p == NULL) {
		*top_p = wk_p;
	}
	else {
		while(1) {
			if (wk2_p->next_p!=NULL) {
				wk2_p = wk2_p->next_p;
				continue;
			}
			wk2_p->next_p = wk_p;
			wk_p->next_p = NULL;
			break;
		}
	}
}

void func_calc(TBL_T **top_p,int q, TBL_T **cmpl_p)
{
	static int cnt=0;
	TBL_T	*wk2_p;

	while(1) {
		wk2_p = *top_p;
		if (wk2_p == NULL) {
			break;
		}
		wk2_p->tm -= q;
		cnt += q; 
		*top_p = wk2_p->next_p;
		wk2_p->next_p=NULL;
		if (wk2_p->tm <= 0) {
			cnt += wk2_p->tm;
			wk2_p->dsp_tm = cnt; 
			/*-- cmpl_p???chain --*/
			func_chain(wk2_p,cmpl_p);
		}
		else {
			/*-- ????°????chain --*/
			func_chain(wk2_p,top_p);
		}
	}
}

void func_dsp(TBL_T *cmpl_p)
{
	TBL_T	*wk2_p;

	wk2_p = cmpl_p;
	while(1) {
		if (wk2_p == NULL) {
			break;
		}
		printf("%s %d\n",&(wk2_p->name[0]),wk2_p->dsp_tm);
		wk2_p = wk2_p->next_p;
	}
}

void func_free(TBL_T **cmpl_p)
{
	TBL_T	*wk2_p;

	while(1) {
		wk2_p = *cmpl_p;
		if (wk2_p == NULL) {
			break;
		}
		*cmpl_p = wk2_p->next_p;
		free(wk2_p);
	}
}

/**------------ SUB ROUTIONE -------------*/
int main()
{
	int     n,q,i;

	char	name[12];
	int		tm;
	TBL_T	*wk_p;
	char 	buff[96];


	/** INIT **/
	top_p = NULL;
	cmpl_p= NULL;
//	num = 0;

	/** INPUT **/
	gets(&(buff[0]));
	sscanf(&(buff[0]),"%d %d",&n,&q);

	for (i=0 ; i<n ; i++) {
		gets(&(buff[0]));
		sscanf(&(buff[0]),"%s %d",name,&tm);
		if ((wk_p=(TBL_T*)malloc(sizeof(TBL_T)))==NULL) {
			return -1;
		}
		wk_p->next_p=NULL;
		strcpy(&(wk_p->name[0]),name);
		wk_p->tm = tm;
		wk_p->fst_tm=tm;
		func_chain(wk_p,&top_p);
	}
	func_calc(&top_p,q,&cmpl_p);
	func_dsp(cmpl_p);
	func_free(&cmpl_p);
	return 0;
}