#include<stdio.h>

int main(){
    int n, q;
    int i;
    char name[50001][10];
    int times[50001];
    int nowtime=0;
    int index[50000];
    int count=0;

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