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

typedef struct {
	char name[12];
	int time, shift;
} process;

int q;

int cmp(const void *a, const void *b) {
	process *pa = (process *)a, *pb = (process *)b;
	return (pa->time - 1) / q - (pb->time - 1) / q;
}

// ???????????????????????????????????¨????????¢?????? O(log n) ??§?§£????????????

int main(void) {
	int now = 0, N, i, j, maxGroup = 0, sum = 0;
	process *ps, **begins;
	int *counts;
	scanf("%d %d", &N, &q);
	ps = malloc(sizeof(process) * N);
	begins = calloc(50000/q, sizeof(process *));
	counts = calloc(50000/q, sizeof(int));
	for (i = 0; i < N; i++) {
		scanf("%s %d", ps[i].name, &ps[i].time);
		for (j = 0; j < (ps[i].time - 1) / q; j++)
			counts[j]++;
		ps[i].shift = counts[j];
		counts[j] = 0;
		if (begins[j] == NULL) begins[j] = &ps[i];
		if (j > maxGroup) maxGroup = j;
	}
	for (i = 0; i <= maxGroup; i++) {
		if (i > 0 && begins[i] != NULL) {
			begins[i]->shift = sum;
			sum = 0;
		}
		sum += counts[i];
	}
	qsort(ps, N, sizeof(process), cmp);
	for (i = 0; i < N; i++) {
		now += ps[i].shift * q + (ps[i].time % q == 0 ? q : ps[i].time % q);
		printf("%s %d\n", ps[i].name, now);
	}

}