#include<stdio.h>

typedef struct {
	int num;
	char name[10];
}QUEUE;

int main() {
	int i, time = 0, n, q, head = 0, tail;
	char s[10];
	QUEUE a[500000];
	scanf("%d", &n);
	scanf("%d", &q);
	for (i = 0; i < n; i++) {
		scanf("%s %d", a[i].name, &a[i].num);
	}
	tail = n;
	i = 1;
	while (head != tail) {
		if (a[head].num > q) {
			a[head].num -= q;
			a[tail] = a[head];
			time += q;
			head++;
			tail++;
		}
		else {
			time += a[head].num;
			printf("%s %d\n", a[head].name, time);
			i++;
			head++;
		}
	}
	return 0;
}



