#include<stdio.h>

int main(){
    int n, q;
    int i, j;
    char name[50001][10];
    int times[50001];
    int nowtime=0;
    int acttime;
    int zerocount=0;

    scanf("%d %d", &n, &q);
    for(i=0;i<n;i++)scanf("%s %d", name[i], &times[i]);

    do{
        for(i=0;i<n;i++){
            if(times[i]==0){
                continue;
            }else if(times[i]>q){
                times[i]-=q;
                nowtime+=q;
            }else{
                zerocount++;
                nowtime+=times[i];
                times[i]=0;
                printf("%s %d\n", name[i], nowtime);
            }
        }
    }while(zerocount!=n);
    return 0;
}

