#include <stdio.h>

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

int n = 0, head = 0, tail = 0;

void enqueue(process_t Q[], process_t a){
    Q[tail] = a;
    if(tail == n - 1){
        tail = 0;
    }
    else{
        tail += 1;
    }
}

process_t dequeue(process_t Q[]){
    if(head == n - 1){
        head = 0;
        return Q[n - 1];
    }
    else{
        head += 1;
        return Q[head - 1];
    }
}

int main( void ){
    int q, i, sum = 0;
    scanf("%d %d", &n, &q);
    process_t Q[n];
    for(i = 0; i < n; i++){
        scanf("%s %d", Q[i].name, &Q[i].time);
    }
    i = 0;
    while(i < n){
        if(Q[head].time <= q){
            sum += Q[head].time;
            printf("%s %d\n", Q[head].name, sum);
            dequeue(Q);
            i++;
        }
        else{
            sum += q;
            Q[head].time -= q;
            enqueue(Q, Q[head]);
            dequeue(Q);
        }
    }
    return 0;
}

