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

int main(void) {
	int n ,q;
	char name[100200][13];
	int time[100200];
	char clearname[100200][13];
	int cleartime[100200];
	int endtime = 0;
	int front = 0;
	int rear;
	int i = 0;

	scanf("%d %d", &n, &q);

	for (rear = 0; rear < n; rear++) {
		scanf("%s %d", name[rear], &time[rear]);
	}

	rear++;
	while (1) {
		if (time[front] > 0) {
			if (time[front] > q) {
				time[front] -= q;
				endtime += q;
				strcpy(name[rear], name[front]);
				time[rear] = time[front];
				rear++;
			}
			else {
				endtime += time[front];
				time[front] = endtime;
				strcpy(clearname[i], name[front]);
				cleartime[i] = time[front];
				i++;
			}

			time[front] = 0;
			memset(name[front], 0, 1);
		}

		if (rear == front) {
			break;
		}

		front++;

	}

	for (i = 0; i < n; i++) {
		printf("%s %d\n", clearname[i], cleartime[i]);
	}

	return 0;
}
