#include <stdio.h>
#include <stdlib.h>

#define LEN 1000000

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

Job Array[LEN+1];
int head, tail;
 
void enqueue(Job*);
void dequeue();

int main() {
    int elaps = 0, n;
    int i, q;

    Job u;

    scanf("%d %d", &n, &q);

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

    while(head != tail)
    {
        dequeue();
        u = Array[0];
        if(u.time > q) {
            u.time -= q;
            enqueue(&u);
            elaps += q;
        }else{
            elaps += u.time;
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}

void enqueue(Job *job) {
    Array[tail] = *job;
    ++tail;
}

void dequeue() {
    Array[0] = Array[head];
    ++head;
}
