/* C */
// ?????\??? P89

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

char name[100001][11];
int time[100001];

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

P Q[100001];

int head;
int tail;

//-------------------------------------------
void enque(P x){
	Q[tail] = x;
	tail = (tail+1)%100001;
}

//-------------------------------------------
P deque(void){
	P x = Q[head];
	head = (head + 1)%100001;
	return	x;
}

//-------------------------------------------
void exe( int q){
	int elaps = 0; //???????????????

	while( head != tail ){
		P x = deque();

		if(x.time - q <= 0){
			// ????????????
			elaps += x.time;
			printf("%s %d\n", x.name, elaps );
		}else{
			// ??????????????????????????£????????§??????????????????????????????
			elaps += q;
			x.time -= q;
			enque(x);
		}
	}
}

int main(int argc, char const *argv[])
{
	int loop;
	int n, q;
	head = 0;
	tail = 0;
	P x;

	scanf("%d %d", &n, &q);

	for(loop = 0; loop < n; ++loop)
	{
		scanf("%s %d", x.name, &x.time);
		enque(x);
	}

	exe(q);

//	printf("========== END!! (^o^)/ ==========\n");

	return 0;
}