#include <stdio.h>

#define MAX 100000

struct data {
    char name[10];
    int time;
};

int head = 0, tail = 0;
struct data Q[100000];

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

void enqueue(struct data p)
{
    Q[tail] = p;
    if (tail == MAX - 1) {
        tail = 0;
    } else {
        tail++;
    }
}

struct data dequeue()
{
    struct data x;
    
    x = Q[head];
    if (head == MAX - 1) {
        head = 0;
    } else {
        head++;
    }
    return x;
}

int main(void)
{
    int n, q, i, t = 0;
    struct data p;
    
    scanf("%d %d", &n, &q);
    for (i = 0; i < n; i++) {
        scanf("%s %d", p.name, &p.time);
        enqueue(p);
    }
    while (isEmpty()) {
        p = dequeue();
        if (p.time <= q) {
            t += p.time;
            printf("%s %d\n", p.name ,t);
        } else {
            t += q;
            p.time -= q;
            enqueue(p);
        }
    }
    return 0;
}
