#include<stdio.h>
#include<string.h>
struct Process
{
    char name[10];
    int tim;
};

struct Process dequeue(struct Process *Q,int *head)
{
    *head = *head + 1;
    return Q[*head - 1];
}

int enqueue(struct Process x,struct Process *Q,int tail)
{
    Q[tail] = x;
    return tail+1;
}


int main()
{
    int n,c,cnt=0,box=0,ksn=0;
    scanf("%d %d",&n,&c);
    int tail=n,head=0;
    char nmtmp[10],tmp;
    struct Process p[n+1];
    for(int i=0;i<n;i++)
    {
        while((tmp=getchar())!=' ')
        {
            if(!(tmp=='\n'||tmp=='\r'))
            {
                nmtmp[cnt] = tmp;
                cnt++;
            }
        }
        strcpy(p[i].name,nmtmp);
        scanf("%d",&box);
        p[i].tim = box;
        cnt=0;
        box=0;
    }
    while(head!=tail)
    {
        if(tail > n) tail = 0;
        struct Process x = dequeue(p,&head);
        if(head > n) head =0;
        //fprintf(stderr,"%s %d\n", x.name,x.tim);
        //printf("%s %d\n", x.name,x.tim);
        if(x.tim < c)
        {
            ksn += x.tim;
            x.tim = 0;
        }
        else 
        {
            ksn += c;
            box = x.tim;
            box -= c;
            x.tim = box;
        }
        if(x.tim == 0)
        {
            printf("%s %d\n", x.name,ksn);
        }
        else
        {
            tail = enqueue(x,p,tail);
        }
    }
    return 0;
}
