#include <stdio.h>

#define MAX 100001

struct process_t {
	char name[11];
	int time;
};

void enqueue(struct process_t *);
struct process_t dequeue(void);

int head=0, tail=0;
struct process_t Q[MAX];

int main(void)
{
	int n, q, i, t=0;
	struct process_t x;
	
	scanf("%d %d", &n, &q);
	for (i=0; i<n; i++) {
		scanf("%s %d", &x.name, &x.time);
		enqueue(&x);
	}
	while (head != tail) {
		x = dequeue();
		if( x.time <= q ) {
			t += x.time;
			printf("%s %d\n", x.name, t);
		} else {
			t += q;
			x.time -= q;
			enqueue(&x);
		}
	}
	
	return 0;
}

void enqueue(struct process_t *x)
{
	Q[tail] = *x;
	tail = (tail + 1) % MAX;
}

struct process_t dequeue(void)
{
	int temp=head;
	head = (head + 1) % MAX;
	return Q[temp];
}