#include <stdio.h>

#define MAXPROCS 100000

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

int main(void)
{
    int i;

    int procs_n, quan;
    scanf("%d %d", &procs_n, &quan);

    proc queue[MAXPROCS];
    for (i = 0; i < procs_n; i++) {
        scanf(" %s %d", queue[i].name, &queue[i].time);
    }

    int timeline = 0;
    int head = 0, tail = procs_n;
    while (head != tail) {
        if (queue[head].time <= quan) {
            timeline += queue[head].time;
            printf("%s %d\n", queue[head].name, timeline);
            head = (head + 1) % MAXPROCS;
        } else {
            timeline += quan;
            queue[head].time -= quan;
            queue[tail] = queue[head];
            head = (head + 1) % MAXPROCS;
            tail = (tail + 1) % MAXPROCS;
        }
    }

    return 0;
}