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

typedef struct {
	char num[11];
	int time;
} Data;

typedef struct {
	Data data;
	Data *bef_p, *aft_p;
} Process;
int main(void){
	int n, last, total = 0, q, i, cnt = 0;
	Process *p_arr, *po, *bef, *aft;
	
	scanf("%d %d\n", &n, &q);
	last = n-1;
	p_arr = (Process*)malloc(sizeof(Process)*n);
	for(i = 0; i < n; i++){
		scanf("%s %d\n", p_arr[i].data.num, &p_arr[i].data.time);
	}
	po = &p_arr[0];
	p_arr[0].bef_p = &p_arr[last];
	p_arr[0].aft_p = &p_arr[1];
	p_arr[last].bef_p = &p_arr[last-1];
	p_arr[last].aft_p = &p_arr[0];
	for(i = 1; i < last; i++){
		p_arr[i].bef_p = &p_arr[i-1];
		p_arr[i].aft_p = &p_arr[i+1];
	}
	po = &p_arr[0];
	while(cnt != n){
		
		if(po->data.time <= q){
			total += po->data.time;
			printf("%s %d\n", po->data.num, total);
			bef = po->bef_p;
			aft = po->aft_p;
			bef->aft_p = po->aft_p;
			aft->bef_p = po->bef_p;
			cnt++;
		}else{
			total += q;
			po->data.time -= q;
		}
		po = po->aft_p;
	}
	return 0;
}

