#include <string.h>
#include <stdio.h>
#include <math.h>
#define N 1000
void enqueue(int);
int dequeue(void);
int isEmpty(void);
int isFull(void);
void initialize(void);
int S[N], head = 0, tail = 0, n, q;
int main(void)
{
	char str[N][11];
	int x, a, cou = 0, time = 0, i, j;
	scanf("%d %d", &n, &q);
	for (i = 0; i < n; i++) {
		scanf("%s %d", str[i], &x);
		enqueue(x);
	}
	a = n;
	for (i = 0; i < a; i++) {
		x = dequeue();
		if (x > q) {
			enqueue(x - q); time += q;
			for (j = 0; str[i][j - 1] != '\0' && str[i - cou][j - 1] != '\0'; j++) {
				str[i - cou][j] = str[i][j];
			}
		}
		else {
			time += x;
			if (i < a) {
				cou++;
				printf("%s %d",str[i],time);
			}
		}
		if (i >= a - 1) {
			i = -1;
			a = a - cou;
			cou = 0;
		}
	}
}
void enqueue(int X)
{
	if (!(isFull())) {
		S[tail] = X;
		if (tail == N - 1) { tail = 0; }
		else tail++;
	}
}
int dequeue(void)
{
	if (!(isEmpty())) {
		if (head == N - 1) { head = 0; return (S[N - 1]); }
		else { head++; return (S[head - 1]); }
	}
}
int isEmpty(void)
{
	if (head == tail) return 1;
	else return 0;
}
int isFull(void)
{
	if (head == (tail + 1) % N) return 1;
	else return 0;

}
void initialize(void)
{
	head = 0; tail = 0;
}