#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
    char name[10];
    int quantum;
}Task;
typedef struct
{
    int tail;
    int head;
    int acSize;
    int maxSize;
}Queue;
void enqueue(Task a,Queue *queue, Task *task);
Task dequeue(Task a,Queue *queue, Task *task);
void getnew (int interval,Queue *queue, Task p[]);
int ifIsFull(Queue *queue);
int main() {
    int interval, size;
    scanf("%d %d",&size, &interval);
    Task task[size];
    Queue queue;
    queue.acSize=0;
    queue.maxSize=size;
    queue.head=0;
    queue.tail=0;
    Task tempTask;
    for(int i = 0; i < size; ++i)
    {
        scanf("%s %d", tempTask.name, &tempTask.quantum);
        enqueue(tempTask, &queue, task);
    }
    getnew(interval,&queue,task); 
    return 0;
}
void enqueue(Task a,Queue *queue, Task *task)
{
    int tail;
    tail = queue->tail;
    if(ifIsFull(queue)==0)
    {
        task[tail] = a;
        queue->tail = (queue->tail+1) % queue->maxSize;
        queue->acSize++;
    }
    if(queue->acSize == queue->maxSize)
    {
        queue->tail = -1;
    }
}
void getnew (int interval,Queue *queue, Task p[])
{
    Task temp;
    int toltime = 0;
    while(queue->head != queue->tail){  
        if(queue->tail < 0 || queue->tail > queue->maxSize - 1)
        {
            queue->tail = queue->head;
        }
        temp = p[queue->head];
        queue->head = (queue->head + 1) % queue->maxSize;
        queue->acSize--;   
        if(temp.quantum <= interval)
        {
            toltime += temp.quantum;
            printf("%s %d\n",temp.name, toltime);
        }
        else 
        {
            toltime += interval;
            temp.quantum -= interval;
           if(ifIsFull(queue)==0)
        {
            p[queue->tail] = temp;
            queue->tail = (queue->tail+1) % queue->maxSize;
            queue->acSize++;
        }
        if(queue->acSize == queue->maxSize)
        {
            queue->tail = -1;
        }
        }
    }
}
int ifIsFull(Queue *queue)
{
    if(queue->acSize < queue->maxSize)
        return 0;
    else 
        return 1; 
}

