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

typedef struct pp{
	char name[10];
	int time;
	int next;
	int last;
}P;

int main() {
	int n,q;
	int counter = 0;
	P val[100000];
	
	int totaltime = 0;
	int usetime = 0;
	
	scanf("%d", &n); //count
	scanf("%d", &q); //quontime
	
	for(int i = 0; i < n; i++){
		scanf("%s", val[i].name);
		scanf("%d", &val[i].time);
		totaltime += val[i].time;
		val[i].next = i + 1;
		val[i].last = i - 1;
	}
	val[n - 1].next = 0;
	val[0].last = n - 1;
	
	int memo_a = -1; //firstplace
	int memo_b = -1; //lastplace
	for(int i = 0;totaltime > usetime;i = val[i % n].next) {
		if(val[i % n].time <= 0){

		}else if(val[i % n].time > q){
			val[i % n].time -= q;
			usetime += q;
		}else{
			usetime += val[i % n].time;
			val[i % n].time = 0;
			val[val[i % n].next].last = val[i % n].last;
			val[val[i % n].last].next = val[i % n].next;
			printf("%s %d\n",val[i%n].name,usetime);
		}
/*		if(i % n == n - 1){
			printf("-----------%d-------------(%d)\n",i,i%n);
			for(int v = 0; v < n; v++){
				printf("%s %d\n",val[v].name,val[v].time);
			}
		printf("memo_a = %d, memo_b = %d\n",memo_a,memo_b);
			printf("-----------%d-------------\n",i);
		}
		if(i > 50){
			break;
		}*/
	}
	return 0;
}
