#include<stdio.h>

typedef struct {
	char name[10];
	int time;
} queue;

int main(){
	int n, q;
	int i, temp;
	int sum = 0;
	int diff;
	int head = 0;
	queue Q[10000];

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

	diff = sum;

	while (sum > 0) {
		
		temp = q > Q[head].time ? Q[head].time : q;
		if (temp != 0) {
			Q[head].time -= temp;
			if (Q[head].time == 0) {
				printf("%s %d\n", Q[head].name, (diff - sum) + temp);
			}
		}

		head++;
		sum -= temp;
		
		if (head >= n) {
			head = 0;
		}
		
	}

	return 0;
}
