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


int main() {
	int n, q;
	int time[100000];
	char name[100000][10];
	char temp[10];
	
	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 j = 0;
	
	for ( i = 0; i < n; i++) {
		if (time[i] > q) {
			count += q;
			time[j] = time[i] - q;
			strcpy(temp, &name[i][0]);
			strcpy(&name[j][0], temp);
			j++;
		} else {
			count += time[i];
			printf("%s %d\n", &name[i][0], count);
		}
		if ( i == n-1 ) {
			if (j > 0) {
				n = j;
				j = 0;
				i = -1;
			}
		}
	}
	
	return 0;
}