#include <stdio.h>

#define N 100000

typedef struct {
    char s[11];
    int time;
} Process;

void enqueue(Process);
Process dequeue();
int isEmpty();
int isFull();

int head = 0;
int tail = 0;
Process p[N];

int main() {
    int i;
    int time, dtime;
    int num;
    Process ip;

    scanf("%d %d", &num, &time);

    for (i = 0; i < num; i++) {
        scanf("%s %d", ip.s, &ip.time);
        enqueue(ip);
    }

    dtime = 0;
    while (!isEmpty()) {

        ip = dequeue();
        ip.time -= time;

        if (ip.time <= 0) {
            dtime += (time + ip.time);
            printf("%s %d\n", ip.s, dtime);
        }
        else {
            dtime += time;
            enqueue(ip);
        }
    }


}

void enqueue(Process process){
    if (isFull()) {
        return;
    }
    if (tail == N) tail = 0;
    p[tail] = process;
    tail++;
}

Process dequeue() {
    Process pr;
    pr.time = -1;
    if (isEmpty()) {
        return pr;
    }
    pr = p[head];
    if (head + 1 == N) {
        head = 0;
    } else {
        head ++;
    }

    return pr;
}

int isEmpty() {
    return head == tail;
}

int isFull() {
    return head == (tail + 1) % N;
}

