#include <stdio.h>

typedef struct
{
    char name[16];
    int time;
} proc;

#define QUEUE_SIZE (200000)
proc queue[QUEUE_SIZE];
int front;
int rear;

void qpush(proc p)
{
    queue[rear] = p;
    rear = (rear + 1) % QUEUE_SIZE;
}

proc qfront(void)
{
    return (queue[front]);
}

void qpop(void)
{
    front = (front + 1) % QUEUE_SIZE;
}

int main(void)
{
    int n, q;
    proc tmp;
    int current;
    int i;

    scanf("%d %d", &n, &q);
    for (i = 0; i < n; i++){
        scanf("%s %d", tmp.name, &tmp.time);
        qpush(tmp);
    }

    current = 0;
    while (front != rear){
        tmp = qfront();
        qpop();

        if (tmp.time <= q){
            current += tmp.time;
            printf("%s %d\n", tmp.name, current);
        }
        else {
            current += q;
            tmp.time -= q;
            qpush(tmp);
        }
    }

    return 0;
}