#include <stdio.h>

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

typedef struct {
    char name[255];
    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 i,n,q;
	int timer=0;
	data_t data;

    queue_head = queue_num = 0;     /* queue ????????¨??????????????????????????????????????°???????????? */
	
	scanf("%d%d", &n, &q);
	
	for(i = 0; i < n; i++){
		process p;
		scanf("%s%d", p.name, &p.time);
		enqueue(p);
	}
	
	while(queue_num > 0){
		dequeue(&data);
		
		if(data.time - q > 0){
			data.time = data.time - q;
			enqueue(data);
			timer += q;
		}else{
			printf("%s %d\n", data.name, timer + data.time);
			timer += data.time;
		}
	}
	
}