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

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

typedef struct {
    Process *processes;
    int size;
    unsigned int head;
    unsigned int tail;
} ProcessQueue;

int getIndex(int index, int buffersize) {
    if(index >= buffersize)
        return index % buffersize;
    return index;
}

void enqueue(ProcessQueue *PQueue, Process process)
{
    if(PQueue->tail >= PQueue->size) {
        PQueue->processes[PQueue->tail++ % PQueue->size] = process;
        return;
    }
    PQueue->processes[PQueue->tail++] = process;
}

Process dequeue(ProcessQueue *PQueue)
{
    if(PQueue->head >= PQueue->size) {
        return PQueue->processes[PQueue->head++ % PQueue->size];
    }
    return PQueue->processes[PQueue->head++];
}

int main(void) 
{
    int i, n, q, eltime = 0;
    Process process;
    ProcessQueue PQueue;

    scanf("%d", &n);
    scanf("%d", &q);
    PQueue.processes = malloc(sizeof(Process) * n);
    PQueue.size = n;
    PQueue.head = PQueue.tail = 0;
    for(i = 0; i < n; i++) {
        scanf("%s", process.name);
        scanf("%d", &process.time);
        enqueue(&PQueue, process); 
    }
    while(PQueue.head != PQueue.tail) {
        process = dequeue(&PQueue);
        if(process.time > q) {
           process.time -= q; 
           eltime += q;
           enqueue(&PQueue, process);
        } else {
           eltime += process.time; 
           printf("%s %d\n", process.name, eltime);
        }
    }


    return 0;
}