#include<stdio.h>

#define QUEUE_SIZE 1000000  /* ?????????????????\????????????????????§??° */
#define SUCCESS     1       /* ?????? */
#define FAILURE     0       /* ??±??? */

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

typedef PROCESS data_t;	/* ???????????? */

data_t queue_data[QUEUE_SIZE]; /* ???????????????????????¬??? */
int queue_head;                /* ??????????????? */
int queue_num;                 /* ??????????????° */

int enqueue(data_t enq_data)
{
    if (queue_num < QUEUE_SIZE) {
        queue_data[(queue_head + queue_num) % QUEUE_SIZE] = enq_data;
        queue_num ++;
        return SUCCESS;
    } else {
        return FAILURE;
    }
}

int dequeue(data_t *deq_data)
{
    if (queue_num > 0) {
        *deq_data = queue_data[queue_head];
        queue_head = (queue_head + 1) % QUEUE_SIZE;
        queue_num --;
        return SUCCESS;
    } else {
        return FAILURE;
    }
}

int main(void){
	int n, q, i;
	int t = 0;	//????????????
	queue_head = 0;
	queue_num = 0;
	data_t process;
	
	scanf("%d %d", &n, &q);
	
	//???????????????n??????????´?
	for(i = 0; i < n; i++){
		scanf("%s %d", process.name, &process.time);
		enqueue(process);
	}
	
	while(queue_num){
		dequeue(&process);
		process.time -= q;
		if(process.time <= 0){
			t += q + process.time;
			printf("%s %d\n", process.name, t);
		}else{
			t += q;
			enqueue(process);
		}
	}
	
	return 0;
}