#include <stdio.h>
#define len 100005

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

Process queue[len];
int head, tail, n;

void enqueue(Process x) {
    queue[tail] = x;
    tail = (tail + 1) % len;
}

Process dequeue(void) {
    Process p = queue[head];
    head = (head + 1) % len;
    return p;
}

int min(int a, int b) { return a < b ? a : b; }

int main(void) {
    int q, i, c, time;
    time = 0;
    Process tmp;
    scanf("%d %d", &n, &q);

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

    head = 0; tail = n + 1;

    while (head != tail) {
        tmp = dequeue();
        c = min(q, tmp.time);
        tmp.time -= c;
        time += c;
        if (tmp.time > 0) enqueue(tmp);
        else if(time > 0) printf("%s %d\n", tmp.name, time);
    }
    return 0;
}

