#include<stdio.h>

void main()
{
    int n,q,cnt = 0,tkm = 0,box=0;
    scanf("%d %d",&n,&q);
    char nm[n][10],tmp,nmflg[n];
    int tm[n],ncnt=n,hcnt[n];
    for(int i=0;i<n;i++){
        while((tmp=getchar())!=' '){
            if(!(tmp=='\n'||tmp=='\r'))
            {
                //printf("tmp=%c\n",tmp);
                //printf("%d行目の%d回目\n",i,cnt);
                nm[i][cnt] = tmp;
                //printf("nm=%c\n",nm[i][cnt]);
                cnt ++;
            }
        }
        scanf("%d",&tm[i]);
        //printf("今回入ったの%d\n",tm[i]);
        nmflg[i]='0';
        hcnt[i] = cnt;
        cnt=0;
    }
    while(ncnt != 0)
    {
        //printf("ncnt=%d\n",ncnt);
        if(cnt == n) cnt = 0;
        if(nmflg[cnt]=='0'){
            if(tm[cnt] < q)
            {
                box = tm[cnt];
                tkm += box;
                tm[cnt] = 0;
            }else {
                tkm += q;
                box = tm[cnt];
                box = box - q;
                tm[cnt] = box;
            }
            if(tm[cnt]==0){
                nmflg[cnt] = '1';
                ncnt -= 1;
                //printf("cnt=%d\n",cnt+1);
                for(int i=0;i<hcnt[cnt];i++){
                    printf("%c",nm[cnt][i]);
                }
                printf(" %d\n",tkm);
            }
        }
        cnt ++;
    }
}
