#include <stdio.h>

#define MAX_N 1010



typedef struct _Elm {
	char name[11];
	int time;

}

Elm;

Elm que[MAX_N];



int main() {

	int n, q, i, cnt, time, t;

	
	scanf("%d %d", &n, &q);
	for(i = 0; i < n; ++i) {
		scanf(" %s %d", que[i].name, &(que[i].time));

	}



	for(i = 0, cnt = 0, time = 0; cnt < n; i = (i+1)%n) {

		if(que[i].time <= 0){
			continue;

		}

		t = q < que[i].time ? q : que[i].time;
		que[i].time -= t;

		time += t;

		if(que[i].time <= 0) {

			printf("%s %d\n", que[i].name, time);

			++cnt;

		}

	}

	return 0;

}

