#include <stdio.h>
#define NAME 10
#define NUM 100000

int head = 0, tail = 0;
typedef struct {
    char name[NAME+1];
    int  time;// if structure variable name is 'res', this variable 'time' means end time. 
}Info;
Info data[NUM+1];
void enqueue( Info );
Info dequeue( void );

int main(){
    int n, quantum, total_time = 0;
    int i, cnt = 0;
    Info tmp, res[NUM];

    //input area
    scanf("%d%d", &n, &quantum);
    for (i = 0; i<n; i++)
	scanf("%s%d", data[i].name, &data[i].time);

    //processing area
    for (tail = n-1;;){
	//when job time is larger than quantum.
	if (data[head].time > quantum){
	    tmp = dequeue();
	    total_time += quantum;
	    tmp.time -= quantum;
	    enqueue(tmp);
	}else {//when job time is smaller than or equal to quantum.
	    tmp = dequeue();
	    total_time += tmp.time;
	    tmp.time = total_time;//update job-time into finished time
	    res[cnt] = tmp;//resister the result
	    cnt++;
	}
	//check the data exist or not	
	if (head == tail+1) break;
    }

    //display area
    for (i = 0; i<n; i++)
	printf("%s %d\n", res[i].name, res[i].time);

    return 0;
}


void enqueue( Info x ){
    //when the tail reached the end of queue.
    if (tail == NUM){
	tail = 0;
	data[tail] = x;
    }else {
	tail++;
	data[tail] = x;
    }
    return ;
}

Info dequeue( void ){
    //when the head reached the end of queue.
    if (head == NUM){
	head = 0;
	return data[NUM];
    }else {
	head++;
	return data[head-1];
    }
}

