#include 	<stdio.h>

#define		STRL		11

typedef struct
{
	char	name[STRL];
	int		time;
}QUEUE;

int		main(void)
{
	int		n, q;
	int		pre = 0;
	int		rear = 0;
	int		cnt = 0;
	int		size;

	scanf("%d",&n);
	scanf("%d",&q);

	size = 2*n;
	QUEUE	Queue[size];

	for( rear = 0; rear < n; rear++ )
	{
		scanf("%s %d",Queue[rear].name, &Queue[rear].time);
	}
	while( pre != rear )
	{
		if( Queue[pre].time <= q )
		{
			cnt += Queue[pre].time;
			printf("%s %d\n",Queue[pre].name,cnt );
		}
		else
		{
			cnt += q;
			Queue[pre].time -= cnt;
			Queue[rear] = Queue[pre];
			rear = (rear + 1) % 20;
		}
		pre = (pre +1) % 20;
	}
	return 0;
}