#include <stdio.h>
#include <stdlib.h>
#define LEN 100005


struct process 
{
	char name[100];
	int time;
};

int main(void)
{
	int n, q;
	// printf("define n, q\n");
	struct process pro[LEN];
	scanf("%d %d", &n, &q);
	int i;
	// printf("n and p get\n");
	for (i = 0; i < n; i++)
		scanf("%s %d", pro[i].name, &pro[i].time);
	// printf("%s %d", pro[1].name, pro[1].time);
	int timecount = 0;
	int head = 0;
	int tail = n;
	while (head != tail)
	{
		if (pro[head].time <= q)
		{
			timecount += pro[head].time;
			printf("%s %d\n", pro[head].name, timecount);
			if (head + 1 < LEN)
			{
				head++;
				continue;
			}
			else
			{
				head = 0;
				continue;
			}
			continue;
		}
		timecount += q;
		pro[head].time -= q;
		// pro[tail].name = pro[head].name;
		for (i = 0; i < 100; i++)
		{
			if (pro[head].name[i] == '\0')
			{
				pro[tail].name[i] = '\0';
				break;
			}
			else
				pro[tail].name[i] = pro[head].name[i];
		}
		pro[tail].time = pro[head].time;
		if (head + 1 < LEN)
		{
			head++;
		}
		else
		{
			head = 0;
		}
		if (tail + 1 < LEN)
		{
			tail++;
		}
		else
		{
			tail = 0;
		}
	}
}

