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

#define NAME_MAX 10

struct process {
    struct process* next;
    char name[NAME_MAX + 1];
    int  time;
};

struct process_queue {
    struct process* head;
    struct process* tail;
    int count;
};

static void enqueue(struct process_queue* queue, struct process* process) {
    if ( queue->head == NULL ) {
        assert( queue->tail == NULL );
        assert( queue->count == 0 );

        queue->head = queue->tail = process;
        queue->tail->next = NULL;
        queue->count++;
    } else {
        queue->tail->next = process;
        queue->tail = process;
        queue->tail->next = NULL;
        queue->count++;
    }

    return;
}

static struct process* dequeue(struct process_queue* queue) {
    assert( queue->head != NULL && queue->tail != NULL );
    assert( queue->count > 0 );

    struct process* head = queue->head;

    if ( queue->head == queue->tail ) {
        assert( queue->count == 1 );
        queue->head = queue->tail = NULL;
    } else {
        queue->head = queue->head->next;
    }

    queue->count--;
    head->next = NULL;

    return head;
}

static int is_empty(struct process_queue* queue) {
    if ( queue->count == 0 ) {
        assert( queue->head == NULL || queue->tail == NULL );
        return 1;
    }
    assert( queue->head != NULL && queue->tail != NULL );
    return 0;
}

/* return elapsed time */
static int schedule(struct process_queue *queue, int q, int now) {
    assert( queue != NULL );
    assert( queue->head != NULL && queue->tail != NULL );
    assert( queue->count > 0 );
    int t;

    struct process* head = dequeue(queue);
    
    if ( head->time > q ) {
        t = q;
        head->time -= q;

        enqueue(queue, head);
    } else {
        t = head->time;

        printf("%s %d\n", head->name, now + t);
        free(head);
    }

    return t;
}

static struct process* read_process(void) {
    char buf[NAME_MAX + 1];
    int  time;
    int  ret;

    ret = fscanf(stdin, "%s %d\n", buf, &time) ;
    if (ret == EOF) {
        return NULL;
    }

    assert( ret == 2 );
    
    struct process* p = (struct process*)malloc(sizeof(struct process));
    assert( p != NULL );
    
    strcpy(p->name, buf);
    p->time = time;
    p->next = NULL;
    
    return p;
}

int main(int argc, char* argv[]) {
    int n, q;
    int ret;
    int i;
    struct process_queue queue = {
        .head = NULL,
        .tail = NULL,
        .count = 0
    };

    ret = fscanf(stdin, "%d %d\n", &n, &q);
    assert( ret == 2);

    for ( i = 0; i < n; i++ ) {
        struct process* p = read_process();
        assert( p != NULL );

        enqueue(&queue, p);
    }

    int t = 0;
    do {
        t += schedule(&queue, q, t);
    } while ( !is_empty(&queue) );

    return 0;
}

