#include<stdio.h>
#include<string.h>
#define m 100000
int ptime[m], overtime[m];
char pname[m][10], overname[m][10];
int main(){
    int i, n, q, xtime=0, l=0, count=0;
    scanf("%d %d", &n, &q);
    for(i=0; i<n; i++)scanf("%s %d", pname[i], &ptime[i]);
    do{
        for(i=0; i<n; i++){
            if(ptime[i]==0);
            else if(ptime[i]-q==0){
                xtime+=q;
                overtime[l]=xtime;
                strcpy(overname[l++], pname[i]);
                ptime[i]=0;
                count++;
            }else if(ptime[i]-q<0){
                xtime+=ptime[i];
                overtime[l]=xtime;
                strcpy(overname[l++], pname[i]);
                ptime[i]=0;
                count++;
            }else if(ptime[i]-q>0){
                xtime+=q;
                ptime[i]-=q;
            }
        }
    }while(count<n);
    for(i=0; i<n; i++)printf("%s %d\n", overname[i], overtime[i]);
    return 0;
}