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

typedef struct node *link;
typedef struct process proc;
typedef proc Item;
struct process {
    char name[11];
    int time;
};
struct node {
    Item item;
    link next;
};
static link head, tail;

void Queueinit (int maxN) { head = NULL; }
int Queueenpty (void) { return head == NULL; }
Item Queueget (void) {
    Item item = head->item;
    link t = head->next;
    free(head);
    head = t;
    return item;
}
link NEW(Item item, link next) {
    link x = malloc(sizeof * x);
    x->item = item;
    x->next = next;
    return x;
}
void Queueput (Item item) {
    if (head == NULL) {
        head = (tail = NEW(item, head));
        return;
    }
    tail->next = NEW(item, tail->next);
    tail = tail->next;
}

int main(void) {
    int n, q, time, i, clock = 0;
    char name[11];
    Item pr;
    Queueinit(1000);
    scanf("%d %d[^\n]", &n, &q);
    if (n < 1 || n > 100000) return -1;
    if (q < 1 || q > 1000) return -1;
    i = 0;
    while (i < n) {
        scanf("%10s %d[^\n]", name, &time);
        pr.time = time;
        strcpy(pr.name, name);
        Queueput(pr);
        i++;
    }
    while (!Queueenpty()) {
        pr = Queueget();
        if (pr.time > q) {
            clock += q;
            pr.time = pr.time - q;
            Queueput(pr);
        } else {
            clock += pr.time;
            printf("%s %d\n", pr.name, clock);
        }
    }
    return 0;
}