#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct link{
    char name[10];
    int time;
    struct link *next;
};

int main (void)
{
    int n,q;
    int now=0;
    int i;
    scanf("%d %d",&n,&q);

    struct link *Q[n];
    
    for(i=0;i<n;i++)
    {
        Q[i]=(struct link *)malloc(sizeof(struct link));
        if(Q[i]==NULL)
        {
            printf("error\n");
            exit(1);
        }
    }

    struct link *END;
    END=(struct link *)malloc(sizeof(struct link));
    if(END==NULL)
    {
        printf("error\n");
        exit(1);
    }
    END->time=0;

    for(i=0;i<n;i++)
    {
        char a[10];
        int t;
        struct link *q;
        scanf("%s %d",a,&t);
        strncpy(Q[i]->name,a,10);
        Q[i]->time=t;
        if(i==n-1)
        {
            Q[i]->next=END;
        }else
        {
            Q[i]->next=Q[i+1];
        }
    }

    struct link *que;
    que=(struct link *)malloc(sizeof(struct link));
    if(que==NULL)
    {
        printf("error\n");
        exit(1);
    }
    struct link *btm;
    btm=(struct link *)malloc(sizeof(struct link));
    if(btm==NULL)
    {
        printf("error\n");
        exit(1);
    }

    que=Q[0];
    btm=Q[n-1];

    while(1)
    {
        //printf("que(%s %d) next(%s %d) now %d\n",que->name,que->time,que->next->name,que->next->time,now);
        if((que->time)>q)
        {
            //printf("big\n");
            now+=q;
            que->time-=q;
            btm->next=que;
            //printf("btm(%s %d) next(%s %d) now %d\n",btm->name,btm->time,btm->next->name,btm->next->time,now);            
            //printf("now que(%s %d) next(%s %d) now %d\n",que->name,que->time,que->next->name,que->next->time,now);
            
            btm=que;
            que=que->next; 
            btm->next=END;
            //printf("btm(%s %d) now %d\n",btm->name,btm->time,now);
            //printf("now que(%s %d) now %d\n",que->name,que->time,now);
        }else
        if((que->time)<=q)
        {
            //printf("small\n");
            now+=que->time;
            printf("%s %d\n",que->name,now);
            if(que->next==END)
            {
                break;
            }else
            {
                que=que->next; 
            }
        }
        //printf("que(%s %d)\n",que->name,que->time);
    }
}


