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

#define true 1

struct Line {
	char name[15];
	int time;
};

int N, Q;
int stack_number = 0;
int count;

int main(void) {
	scanf("%d %d", N, Q);

	struct Line line[N + 1];
	int stack[N+1];
	memset(stack, '\0');

	for (int i = 0; i < N; i++) {
		scanf("%s %d", line[i].name, line[i].time);
		line[i].number = i;
		stack[i] = i;
		stack_number = i;
	}
	
	
	while (true) {
		if (line[stack[0]].time > Q) {
			line[stack[0]].time -= Q;
			stack[stack_number + 1] = stack[0];
			for (int i = 0; i <= stack_number; i++) {
				stack[i] = stack[i + 1];
			}
			count += Q;
		}
		else {
			count += stack[0].time;
			printf("%s %d\n", line[stack[0]].name, count);
			for (int i = 0; i < stack_number; i++) {
				stack[i] = stack[i + 1];
			}
			stack_number--;
			if (stack_number == -1) {
				return 0;
			}
		}
	}
}