#include <stdio.h>
#include <stdlib.h>

typedef struct _data
{
	char name[11];
	int time;
	struct _data *next;
} data;

void enq(data **h, data **t, data *p)
{
	p->next = NULL;
	if (*t == NULL) *h = p;
	else (*t)->next = p;
	*t = p;
}

data *deq(data **h, data **t)
{
	data *w;
	if (*h == NULL) return NULL;
	w = *h;
	*h = (*h)->next;
	if (*h == NULL) *t = NULL;
	return w;
}

int main()
{
	int n, q, c, i;
	data *h, *t, *p;

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

	h = t = NULL;
	for (i = 0; i < n; i++)
	{
		p = (data*)malloc(sizeof(data));
		scanf("%10s",p->name);
		scanf("%d",&(p->time));
		enq(&h,&t,p);
	}

	c = 0;
	while ((p = deq(&h,&t)) != NULL)
	{
		if (p->time <= q)
		{
			c += p->time;
			p->time = 0;
		}
		else
		{
			c += q;
			p->time -= q;
		}

		if (p->time == 0)
		{
			printf("%s %d\n",p->name,c);
			free(p);
		}
		else
			enq(&h,&t,p);
	}

	return 0;
}