#define QSIZE 50000
#include<stdio.h>
#include<stdlib.h>

struct Queue {
	char name[1000];
	int time;
};

int head = 0, tail = 0, n;
struct Queue Q[QSIZE];

void enqueue(struct Queue);
struct Queue dequeue(void);


int main() {
	struct Queue a;
	int q, i, t = 0, j = 0;
	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++) scanf("%s %d", Q[i].name, &Q[i].time);
	while (j != n) {
		a = dequeue();
		if (a.time <= q) {
			t += a.time;
			printf("%s %d\n", a.name, t);
			++j;
		}
		else {
			t = q + t;
			a.time =  a.time - q;
			enqueue(a);
		}
	}
	
	return 0;
}


void enqueue(struct Queue a) {
  int next;

	Q[tail] = a;
	if (tail + 1 == n) tail = 0;
	else ++tail;
}
struct Queue dequeue(void) {
	struct Queue a;
	a = Q[head];
	if (head + 1 == n) head = 0;
	else ++head;
	return a;
}

