#include <stdbool.h>
#include <stdio.h>

#define SIZE 100001

typedef struct Process_
{
    char name[11];
    int time;
} Process;

Process Q[SIZE];
int head;
int tail;

static void enqueue(Process x)
{
    Q[tail] = x;
    tail = (tail + 1) % SIZE;
}

static Process dequeue()
{
    Process x = Q[head];
    head = (head + 1) % SIZE;
    return x;
}

static bool isEmpty()
{
    return head == tail;
}

static int min(int a, int b)
{
    return a < b ? a : b;
}

int main()
{
    int n, q;
    int elapsed = 0;

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

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

    while (!isEmpty()) {
        Process p = dequeue();
        int t = min(q, p.time);
        p.time -= t;
        elapsed += t;

        if (p.time > 0) {
            enqueue(p);
        } else {
            printf("%s %d\n", p.name, elapsed);
        }
    }

    return 0;
}
