#include<stdio.h>
# define LEN 100010

typedef struct {
    char name[20];
    int time;
} Process;

typedef struct {
    Process q_array[LEN];
    int head;
    int tail;
} Queue;

void init_queue(Queue *queue){
    queue->head = 0;
    queue->tail = 0;
}

void enque(Queue *queue, Process p){
    queue->q_array[queue->tail] = p;
    queue->tail = (queue->tail == LEN - 1) ? 0 : queue->tail + 1;
}

Process deque(Queue *queue){
    int head_tmp;
    head_tmp = queue->head;
    queue->head = (queue->head == LEN -1) ? 0 : queue->head+1;
    return queue->q_array[head_tmp];
}

int main(void){
    int i, n, q;
    int time = 0;
    Queue queue;
    Process p_tmp;

    // set the value of queue
    init_queue(&queue);
    scanf("%d", &n);
    scanf("%d", &q);
    for(i = 0; i < n; i++){
        scanf("%s", p_tmp.name);
        scanf("%d", &p_tmp.time);
        enque(&queue, p_tmp);
    }

    while(queue.head != queue.tail){
        p_tmp = deque(&queue);
        if(p_tmp.time > q){
            time += q;
            p_tmp.time -= q;
            enque(&queue, p_tmp);
        }
        else{
            time += p_tmp.time;
            printf("%s %d\n", p_tmp.name, time);
        }
    }

    return 0;
}

