#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define MIN(x, y) ((x) <= (y) ? (x) : (y))
typedef struct QueueKey {
    char str[16];
    int num;
} QueueKey;
typedef struct QueueDat {
    QueueKey key;
    struct QueueDat *next;
} QueueDat;
typedef struct Queue {
    size_t len;
    QueueDat *head;
    QueueDat *tail;
} Queue;
#define queue_init(q) ((q) ? ((q)->len = 0, (q)->head = (q)->tail = NULL) : 0)
#define queue_len(q) ((q) ? (q)->len : 0)
void queue_push(Queue *q, QueueKey x) {
    QueueDat *new_dat = malloc(sizeof(QueueDat));
    *new_dat = (QueueDat){x, NULL};
    if(q->len) {
        q->tail->next = new_dat;
        q->tail = new_dat;
    }else{
        q->head = q->tail = new_dat;
    }
    q->len++;
}
QueueKey queue_pop(Queue *q) {
    assert(q->len);
    QueueDat *old_head = q->head;
    q->head = old_head->next;
    QueueKey key = old_head->key;
    free(old_head);
    q->len--;
    return key;
}

int main(int argc, char **argv) {
    int n, q;
    scanf("%d%d", &n, &q);
    Queue Q;
    queue_init(&Q);
    QueueKey key;
    for(int i = 0; i < n; ++i) {
        scanf("%s%d", key.str, &key.num);
        queue_push(&Q, key);
    }
    int cnt = 0;
    while(queue_len(&Q)){
        key = queue_pop(&Q);
        cnt += MIN(key.num, q);
        if(key.num > q){
            key.num -= q;
            queue_push(&Q, key);
        } else {
            printf("%s %d\n", key.str, cnt);
        }
    }
    return 0;
}

