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

typedef struct tagItem Item;
typedef struct tagNode Node;
struct tagItem {
    char name[16];
    int time;
};
struct tagNode {
    Item item;
    Node *prev;
    Node *next;
};

void push(Node *queue, Item *item)
{
    //printf("push %s %d\n", item->name, item->time);
    Node *node = (Node *)malloc(sizeof(Node));
    node->item = *item;
    node->prev = queue->prev;
    node->next = NULL;
    if (queue->next == NULL) {
        queue->next = node;
    } else {
        queue->prev->next = node;
    }
    queue->prev = node;
}

int pop(Node *queue, Item *item)
{
    //printf("pop %p\n", queue->next);
    Node *node = queue->next;
    if (node != NULL) {
        if (node->next != NULL) {
            node->next->prev = NULL;
        }
        queue->next = node->next;
        if (queue->next == NULL) {
            queue->prev = NULL;
        }
        *item = node->item;
        free(node);
        //printf("pop %s %d\n", item->name, item->time);
        return 1;
    }
    //printf("pop error\n");
    return 0;
}

int main(void)
{
    Node queue;
    queue.prev = NULL;
    queue.next = NULL;
    int n, q, i, t;
    Item item;
    scanf("%d%d", &n, &q);
    for (i = 0; i < n; ++i) {
        scanf("%s%d", item.name, &item.time);
        push(&queue, &item);
    }
    t = 0;
    while(pop(&queue, &item)) {
        if (item.time <= q) {
            t += item.time;
            printf("%s %d\n", item.name, t);
        } else {
            t += q;
            item.time -= q;
            push(&queue, &item);
        }
    }

    return 0;
}

