// includes
#include <stdio.h>
#include <string.h>

// defines
#define LEN 100005


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


// deque target
int head;
// enqueue target
// tail is Queue length.
int tail;
// process count
int N;
// quontum time
int qms;

// Queue
Process Q[LEN];


// enqueue process to Queue
void enqueue(Process p) {
    Q[tail] = p;
    tail = (tail + 1) % LEN;
}

// dequeue process to Queue
Process dequeue() {
    Process p = Q[head];
    head = (head + 1) % LEN;
    return p;
}


void runProcess() {
    // elapsed time
    int et = 0;

    while (head != tail) {
        Process p = dequeue();
        if (p.time > qms) {
            p.time -= qms;
            enqueue(p);
            et += qms;
        } else {
            et += p.time;
            printf("%s %d\n", p.name, et);
            p.time = 0;
        }
    }
}

int main() {
    // initialize head
    head = 0;

    // scan
    scanf("%d %d", &N, &qms);
    for (int i = 0; i < N; i++) { scanf("%s %d", Q[i].name, &Q[i].time); }

    // initialize tail
    tail = N;

    runProcess();

    return 0;
}

