#include <stdio.h>

#define Max 100000

struct queue {
	char name[10];
	int time;
	int jump;
}; typedef struct queue queue;

queue A[Max];

void  swap(queue *x, queue *y)
{
    queue  buff;
	
	buff = *x;
	*x = *y;  
	*y = buff;
}

int main( ) {
	int n, q, i, j, total_time, new_i, count;

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

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

	j = n;
	i = 0;
	total_time = 0;

	while (j > 0) {
		new_i = 0;
		count = 0;
		for (i = 0; i < j; i++) {
			if (A[i].time <= q) {
				total_time += A[i].time;
				printf("%s %d\n", A[i].name, total_time);
				count++;
			}
			else {
				total_time += q;
				A[i].time -= q;
				swap(&A[new_i++], &A[i]);
			}
		}
		j -= count;
	}

	return 0;
}