#include<stdio.h>
#define MAX 131072
typedef struct _task{
    char name[11];
    int time;
} task;
task Q[MAX];
int head, tail;
void initialize();
void enq(task);
task deq();
int isFull();
int isEmpty();
int main(void){
    int i, q, N, time_passed = 0;
    task t;
    scanf("%d %d", &N, &q);
    for(i = 0; i < N; i++){
        scanf("%s %d", t.name, &t.time);
        enq(t);
    }
    while(!(isEmpty())){
        t =deq();
        if(t.time <= q){
            time_passed += t.time;
            printf("%s %d\n", t.name, time_passed);
        } else {
            t.time -= q;
            time_passed += q;
            enq(t);
        }
    }

    return 0;
}
void initialize(){
    head = 0;
    tail = 0;
    return;
}
int isFull(){
    return (head + 1) % MAX == tail;
}
int isEmpty(){
    return head == tail;
}
void enq(task data){
    if(isFull()){
        printf("queue.overflow");
        return;
    }
    Q[head] = data;
    if(head == MAX - 1){
        head = 0;
    } else head++;
    return;
}
task deq(){
    task error_return; 
    task t;   

    if(isEmpty()){
        printf("queue.nodata");
        return error_return;
    }
    t = Q[tail];
    if(tail == MAX - 1){
        tail = 0;
    } else tail++;
    return t;
}

