#include<stdio.h>
#include<string.h>
typedef struct
{
    char name[10];
    int time;
}Task;
Task Q[100001];
int head=1, tail=1, n;
void enqueue(Task x)
{
    Q[tail]=x;
    if(tail==n) tail=1;
    else tail++;
}
Task dequeue(void)
{
    if(head==(n+1)) head=2;
    else head++;
    return Q[head-1];
}
int main()
{
    Task u;
    int q, time, i, count=0;
    long int sum;
    char name[10];

    scanf("%d %d", &n, &q);

    for(i=1;i<=n;i++)
        scanf("%s %ld", &Q[i].name, &Q[i].time);

    while(count!=n)
    {
        u=dequeue();
        if(u.time<=q)
        {
            sum+=u.time;
            printf("%s %d\n", u.name, sum);
            count++;
        }
        else
        {
            sum+=q;
            u.time-=q;
            enqueue(u);
        }
    }

    return 0;
}