#include<stdio.h>
#include<stdlib.h>
#define LEN 100000

struct mission
{
    char name[10];
    int time;
};
typedef struct mission mission;

int head ,tail;
mission Q[LEN];

int isEmpty()
{
    return head == tail;
}
int isFull()
{
    return head == (tail + 1)%LEN;//isFull
}
void enqueue(mission x)
{
    if (isFull())
        printf("Wrong!!No More");
    else
    {
     Q[tail] = x;
    tail = (tail + 1) % LEN;
    }
}
mission dequeue()
{
    if (isEmpty())
        printf("Wrong!!Already Empty");
    mission x = Q[head];
    head = (head + 1) % LEN;
    return x;
}
//返回最小值
int min(int a,int b)
{
    return a < b ? a : b;
}
int main()
{
    int elaps = 0,c;
    int m,n,i;
    mission u;
    scanf("%d %d",&m,&n);
    //按顺序将所有任务添加至队列
    for(i = 1;i <= m;i++)
    {
        scanf("%s%d",Q[i].name,&Q[i].time);
    }
    head = 1,tail = m+1;
    //模拟
    while(!isEmpty())
    {
        u = dequeue();
        c = min(n,u.time);//执行时间片q或所需时间u.t的处理
        u.time -= c;//计算剩余的所需时间
        elaps += c;//计算已经过的时间
        if(u.time > 0)//如果处理尚未结束则重新添加至队列
        {
            enqueue(u);
        }
        else
        {
            printf("%s %d\n",u.name,elaps);
        }
    }
    return 0;
}


