#include <stdio.h>
#define MAX 100001
#define min(a, b) ((a) < (b) ? (a) : (b))

typedef struct process {
    char name[10];
    int time;
} P;


P Q[MAX];
int head, tail;
int finish;


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

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

void enqueue(P proc) {
    Q[tail++] = proc;
    tail = tail % MAX;
}

P dequeue() {
    P x;
    x= Q[head++];
    head = head % MAX;
    return x;
}

int main() {

    int n, q, t;

    scanf("%d %d", &n, &q);
    head = 0;
    tail = n;
    finish = 0;
    for (int i = 0; i < n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].time);
    }
    while (!isEmpty()) {
        P x;
        x = dequeue();
        t = min(x.time, q);
        finish += t;
        x.time -= q;
        if (x.time > 0) enqueue(x);
        else printf("%s %d\n", x.name, finish);
    }



    return 0;
}
