#include <stdio.h>
#include <limits.h>

#define LENGTH 50005

typedef struct queue {
    char name[100];
    int value;
} Queue;

Queue q[LENGTH];
int front;
int tail;

Queue pop()
{
    Queue tmp = q[front];
    front = (front + 1) % LENGTH;
    return tmp;
}

void push(Queue x)
{
    q[tail] = x;
    tail = (tail + 1) % LENGTH;
}

int main()
{
#ifdef TEST
    freopen("input", "r", stdin);
#endif

    int num, period;
    scanf("%d %d", &num, &period);
    Queue tmp;
    for (int i = 0; i < num; ++i) {
        scanf("%s %d", tmp.name, &tmp.value);
        push(tmp);
    }

    int cnt = 0;
    int time = 0;
    while (cnt < num) {
        Queue tmp = pop();
        if (tmp.value <= period) {
            time += tmp.value;
            cnt++;
            printf("%s %d\n", tmp.name, time);
        } else {
            time += period;
            tmp.value -= period;
            push(tmp);
        }

    }

    return 0;
}

