#include<stdio.h>

typedef struct Process_
{
    char name[11];
    int tim;
} process;
 
#define Q_TAIL 100000;

typedef struct Queue_
{
    process p[Q_TAIL];
    int head;
    int tail;
} queue;


process dequeue(queue *q)
{
    int b = q->head;
    q->head = (q->head+1)%Q_TAIL;
    return q->p[b];
}

void enqueue(queue *q,process x)
{
    q->p[q->tail] = x;
    q->tail +=1;
    q->tail = q->tail%Q_TAIL;
}

int queue_empty(queue *q)
{
    return q->head == q->tail;
}

int main()
{
    int n,c,ksn=0;
    scanf("%d %d",&n,&c);
    queue q;
    for(int i=0;i<n;i++)
    {
        process p;
        scanf("%s", p.name);
        scanf("%d", &p.tim);
        enqueue(&q,p);
    }
    while(!(queue_empty(&q)))
    {
        process x = dequeue(&q);
        if(x.tim < c)
        {
            ksn += x.tim;
            x.tim = 0;
        }
        else
        {
            ksn += c;
            x.tim -= c;
        }
        if(x.tim == 0)
        {
            printf("%s %d\n", x.name,ksn);
        }
        else
        {
            enqueue(&q,x);
        }
    }
    return 0;
}
