#include <stdio.h>
#include <string.h>
#define LEN 100001

typedef struct process {
    char name[11];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    if (tail == n)
        tail = 0;
    else
        tail += 1;
}

P dequeue() {
    P tp = Q[head];
    if (head == n)
        head = 0;
    else
        head += 1;
    return tp;
}

int main() {
    int q;
    scanf("%d %d", &n, &q);

    int i;
    for (i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }

    head = 1;
    tail = 0;
    P p;
    int elaps = 0;

    while (head != tail) {
        p = dequeue();
        if (p.t > q) {
            p.t -= q;
            elaps += q;
            enqueue(p);
        } else {
            elaps += p.t;
            printf("%s %d\n", p.name, elaps);
        }
    }

    return 0;
}

