#include<stdio.h>
#include<stdlib.h>

typedef struct{
	char num[11];
	int time;
} Process;
int main(void){
	int n, total = 0, q, i, cnt = 0;
	Process *p;
	scanf("%d %d\n", &n, &q);
	p = (Process*)malloc(sizeof(Process)*n);
	for(i = 0; i < n; i++){
		scanf("%s %d\n", p[i].num, &p[i].time);
	}
	i = 0;
	while(cnt != n){
		if(i == n){
			i = 0;
		}
		if(p[i].time <= 0){
			i++;
			continue;
		}
		if(p[i].time <= q){
			total += p[i].time;
			printf("%s %d\n", p[i].num, total);
			p[i].time = 0;
			cnt++;
		}else{
			total += q;
			p[i].time -= q;
		}
		i++;
	}
	return 0;
}

