#include <stdio.h>

#define N_MAX (100000)

typedef struct {
	char name[11];
	int time;
} PROC;

int main(void) {
	int n, q;
	PROC proc[N_MAX];
	int i, c, t;
	
	scanf("%d %d", &n, &q);
	
	for (i = 0; i < n; ++i) {
		scanf("%s %d", proc[i].name, &proc[i].time);
	}
	
	t = 0;
	do {
		c = 0;
		for (i = 0; i < n; ++i) {
			if (proc[i].time) {
				if (proc[i].time > q) {
					t += q;
					proc[i].time -= q;
				} else {
					t += proc[i].time;
					proc[i].time = 0;
					printf("%s %d\n", proc[i].name, t);
				}
				++c;
			}
		}
	} while (c);
	
	return 0;
}