#include<stdio.h>
#include<time.h>
 
#define MAX 100005 
 
typedef struct tq{
    char name[100];
    int time;
} s;
 
int head, tail, n;
s Q[MAX];
 
s dequeue()
{
    s t; 
    t = Q[head];
    head = (head + 1) % MAX;
    return t;
}
 
void enqueue(s x)
{
    Q[tail] = x;
    tail = (tail + 1) % MAX;
}
 
int main()
{
    int q, n, i, count;
    s x;
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    scanf("%d", &n);
    count = n;
    scanf("%d", &q);
    for(i=0;i<n;i++)
    {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].time);
        enqueue(Q[i]);
    }
    i = 0;
    while(head!=tail)
    {
        if(Q[head].time>q)
        {
            Q[head].time -= q;
            enqueue(dequeue());
            i += q;
        } 
        else
        {
            x = dequeue();
            i += x.time;
            printf("%s ", x.name);
            printf("%d\n", i);
        }
    }
    //printf("%lf\n",(double)clock()/CLOCKS_PER_SEC);
    return 0;
}