#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define  MAX 100000

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

int head, tail;
Proce data[MAX];

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(Proce x);
Proce dequeue(void);
int min(int a, int b);

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

    initialize();

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

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

    head = 1;
    tail = n + 1;

    while (head != tail) {
        Proce x;

        x = dequeue();

        int value;
        value = min(x.time, q);

        x.time -= value;
        sum += value;

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

void initialize(void)
{
    head = tail = 0;
}

int isEmpty(void)
{
    if (head == tail) {
        return 1;
    } else {
        return 0;
    }
}

int isFull(void)
{
    if (head == (tail + 1) % MAX) {
        return 1;
    } else {
        return 0;
    }
}

void enqueue(Proce x)
{
    if (isFull()) {
        printf("エラー（オーバーフロー）\n");
    }

    data[tail] = x;
    tail = (tail + 1) % MAX;
}

Proce dequeue(void)
{
    Proce x;

    if (isEmpty()) {
        printf("エラー（アンダーフロー）\n");
    }

    x = data[head];

    head = (head + 1) % MAX;

    return x;
}

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

