#include <stdio.h>
#include <string.h>
#define LEN 100001

int head, tail;
typedef struct pp{
	char name[100];
	int t;
} p;
p Quene[LEN];

void enquene(p x){
	Quene[tail] = x;
	tail = (tail + 1) % LEN;
}
p dequene(){
	p x = Quene[head];
	head = (head + 1) % LEN;
	return x;
}
int min(int a, int b){
	if (a < b){
		return a;
	}else{
		return b;
	}
}
int main() {
	int n, q;
	int sumtime = 0, c;
	p u;
	scanf("%d %d", &n, &q);
	head = 0;
	tail = n;
	int i;
	for(i = 0; i<n; i++){
		scanf("%s", Quene[i].name);
		scanf("%d", &Quene[i].t);
	}
	while (head != tail) {
		u = dequene();
		c = min(q, u.t);
		u.t -= c;
		sumtime += c;
		if (u.t > 0) {
			enquene(u);
		}else {
			printf("%s %d\n", u.name, sumtime);
		}
	}
	return 0;
}