#include<stdio.h>

char name[100000][16];
int time[100000];
int queue[1000001];

int main(){
	int n = 0, q = 0;
	int sq = 0, eq = 0;
	int i = 0, j = 0;
	int t = 0;
	int tt = 0;	//???????????????
	scanf("%d %d", &n, &q);
	for( i = 0; i < n; i++ ){
		scanf("%s %d", name[i], &time[i]);
		queue[eq++] = i;
	}
	for( t = 0; sq != eq; t += tt ){
		i = queue[sq++];
		if( time[i] <= q ){
			tt = time[i];
			printf("%s %d\n", name[i], t+time[i]);
			time[i] = 0;
		}else{
			time[i] -= q;
			tt = q;
			queue[eq++] = i;
		}
		sq %= 1000001;
		eq %= 1000001;
	}
	return 0;
}