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

#define N_MAX 100000
#define NAME_LEN 10

struct q {
	char name[NAME_LEN+1];
	int time;
	struct q *next;
};

int
main(void)
{
	int i, n, qtm;
	struct q *head = NULL;
	struct q *tail = NULL;
	int time = 0;

	scanf("%d", &n);
	scanf("%d", &qtm);
	for (i = 0; i < n; i++) {
		struct q *a = (struct q *)malloc(sizeof(struct q));
		if (a == NULL)
			return 1;
		scanf("%s", a->name);
		scanf("%d", &a->time);
		a->next = NULL;
		if (head == NULL)
			head = a;
		if (tail == NULL) {
			tail = a;
		} else {
			tail->next = a;
			tail = a;
		}
	}

	while (n) {
		if (head->time <= qtm) {
			struct q *a = head;
			time += a->time;
			printf("%s %d\n", a->name, time);
			head = a->next;
			free(a);
			n--;
			continue;
		}
		head->time -= qtm;
		time += qtm;
		tail->next = head;
		tail = head;
		head = head->next;
	}

  return 0;
}

