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

int main(void)
{
	int  pn;					/* process num */
	int  pt;					/* process time */
	char name_buff[100000][10];	/* Name Buffer */
	int  time_buff[100000];		/* Time Buffer */
	int  data_num = 0;
	int  bp = 0;				/* Buffer Position */
	
	/* get "process num" & "process time" */
	scanf("%d %d", &pn, &pt);
	
	/* get Name & time */
	while(scanf("%s %d", name_buff[data_num], &(time_buff[data_num])) != EOF)
	{
		data_num++;
	}
	
	/* get Data Num equal process num */
	if( data_num == pn )
	{
		while(pn > 0)
		{
			/* remain process time */
			if(time_buff[bp] > 0)
			{
				if( time_buff[bp] > pt )
				{
					time_buff[bp] -= pt;
				}
				else
				{
					printf("%s %d\n", name_buff[bp], time_buff[bp]); /* output finished process */
					time_buff[bp] = 0;
					pn--;
				}
			}
			else
			{
				/* Already Finish */
			}
			
			/* Next buffer position */
			if(bp == data_num)
			{
				bp = 0;
			}
			else
			{
				bp++;
			}
		}
	}
	else
	{
		/* error input */
	}
	
	return 0;
}