#include <stdio.h>

#define Q_LEN 100005

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

static PROCESS Q[Q_LEN+1];
static int head, tail, process_num;

void
enqueue(PROCESS process_data)
{
        Q[tail] = process_data;

        if (Q_LEN < (tail + 1))
                tail = 0;
        else
                tail++;
}

PROCESS
dequeue(void)
{
        PROCESS process_data;

        process_data = Q[head];

        if (Q_LEN < (head + 1))
                head = 0;
        else
                head++;
        return process_data;
}

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


int
main(void)
{
        int quantum;
        PROCESS process;
        int current_time = 0;
        int i;

        initialize();

        scanf("%d %d", &process_num, &quantum);

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

        i = 1;
        while (i <= process_num) {
                process = dequeue();
                process.time -= quantum;

                if (0 < process.time) {
                        current_time += quantum;
                        enqueue(process);
                } else if (process.time <= 0) {
                        current_time += (quantum + process.time);
                        printf("%s %d\n", process.name, current_time);
                        i++;
                }
        }
        return 0;
}

