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


int main() {
	int n, q;
	int time[100000];
	char name[10][100000];
	
	scanf("%d %d", &n, &q);
	int i;
	for(i = 0; i < n; i++) {
		scanf("%s %d", &name[i][0], &time[i]);
	}
	int count = 0;
	int exist = 1;
	
	for ( i = 0; i < n; i++) {
		if ( time[i] == 0 )
			;
		else if (time[i] > q) {
			exist = 1;
			count += q;
			time[i] -= q;
		} else {
			count += time[i];
			time[i] = 0;
			printf("%s %d\n", &name[i][0], count);
		}
		if ( i == n-1 ) {
			if (exist) {
				exist = 0;
				i = -1;
			}
		}
	}
	
	return 0;
}