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

#define NAME_LENGTH 10

typedef struct {
	char name[NAME_LENGTH+1];
	int remain_time;
} Process;

typedef struct {
	void **list;
	int size;
	int count;
	int head;
	int tail;
} Que;

Que* que_create(int size){
	Que *que;

	que = malloc(sizeof(Que));
	que->list = malloc(sizeof(void*)*size);
	que->size = size;
	que->count = 0;
	que->head = -1;
	que->tail = -1;

	return que;
}

void que_delete(Que *que){
	free(que->list);
	free(que);
}

int que_add_tail(Que *que, void *p){
	int ok = 0;

	if( que->count < que->size ){
		ok = 1;
		que->tail = (que->tail + 1 ) % que->size;
		que->list[que->tail] = p;
		que->count++;
		if( que->count == 1 ){
			que->head = que->tail;
		}
	}

	return ok;
}

void* que_take_head(Que *que){
	void *p = NULL;

	if( que->count > 0 ){
		p = que->list[que->head];
		que->head = (que->head + 1 ) % que->size;
		que->count--;
	}

	return p;
}

int main(int argc, char** argv){
	// Input Pamameter Variable
	Process *list;
	int n,q;
	// Work Variable
	Que *que;
	Process *p;
	int i,curr_time;

	// Input & Create Process List/Que
	scanf("%d%d",&n,&q);
	list = malloc(sizeof(Process) * n);
	que = que_create(n);
	for(i=0;i<n;i++){
		scanf("%10s%d",list[i].name,&list[i].remain_time);
		que_add_tail(que,list+i);
	}

	// Check & Output
	curr_time = 0;
	for(;;){
		// Get Next Process
		p = (Process*)que_take_head(que);
		if( p == NULL ){
			// All Process Finish
			break;
		}
		// Remain Time Check
		if( p->remain_time <= q ){
			// Time Forward
			curr_time += p->remain_time;
			// Process Finish
			p->remain_time = 0;
			// Output
			printf("%s %d\n",p->name,curr_time);
		} else {
			// Time Forward
			curr_time += q;
			// Process Not Finish -> Back To Que Tail
			p->remain_time -= q;
			que_add_tail(que,p);
		}
	}

	// Delete Process List/Que
	free(list);
	que_delete(que);

	return 0;
}