#include<stdio.h>
#define LEN 100000
typedef struct task{
    char name[100];
    int time;
}P;
P tasks[LEN];
int head=0,tail=0;
int n,q;
int fTime=0;
int count;
int min(int x,int y)
{
    return x<y?x:y;
}
void enqueue(P x)
{
    tasks[tail]=x;
    tail++;
    if(tail>n-1) tail=tail-n;
}
void dequeue()
{
    head++;
    if(head>n-1) head=head-n;
}
int main()
{

    scanf("%d%d",&n,&q);
    count=n;
    for(int i=0;i<n;i++)
    {
        P itask;
        scanf("%s",itask.name);
        scanf("%d",&itask.time);
        enqueue(itask);
    }
    while(count>0)
    {

        int flagTime=min(tasks[head].time,q);
        fTime=fTime+flagTime;
        tasks[head].time=tasks[head].time-flagTime;
        if(tasks[head].time==0)
        {
            printf("%s %d\n",tasks[head].name,fTime);
            dequeue();
            count--;
        }
        else
        {
            enqueue(tasks[head]);
            dequeue();
        }
    }

    return 0;
}

