#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int quon, sp = 0;
int count = 0;

int main(void){
	int input, i;
	int total = 0, maxTotal = 0;
	scanf("%d %d", &input, &quon);
	int box[input], check[input];
	char tag[input][100];

	for(i = 0; i < input; i++){
		scanf("%s %d",tag[i], &box[i]);
		maxTotal += box[i];
		check[i] = 1;
	}
	if(input == 1){
		printf("%s %d\n",tag[i], &box[i]);
		return 0;
	}

	while(1){
		if(quon >= box[sp] && check[sp]){
			total += box[sp];
			box[sp] = 0;
			check[sp] = 0;
			printf("%s %d\n",tag[sp], total);
			count++;
			if(count > input - 2) break;
		} else {
			if(box[sp] > 0){
				box[sp] -= quon;
				total += quon;
			}
		}
		sp = (sp+1)%input;
	}
	for(i = 0; i < input; i++){
		if(check[i]) break;
	}
	printf("%s %d\n",tag[i], total+box[i]);
	return 0;
}