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

typedef struct
{
    char name[20];
    int exe_time;
    int fin_time;
}process;

int check_all_0(process *p, int num){
    for(int i=0; i<num; i++){
        if(p[i].exe_time != 0) return 0;
    }
    return 1;
}

int compare_fin_time(const void*a, const void*b){
    process *pa = (process *)a;
    process *pb = (process *)b;
    

    return pa->fin_time - pb->fin_time;
}

int main()
{
    int process_num, rr_time;
    scanf("%d %d", &process_num, &rr_time);
    
    process *proc = malloc(process_num*sizeof(process));
    for(int i=0; i<process_num; i++){
        scanf("%s %d", proc[i].name, &proc[i].exe_time);
        proc[i].fin_time = 0;
    }

    int total_time = 0;
    while(!check_all_0(proc,process_num)){
        for(int i=0; i<process_num; i++){
            if(proc[i].exe_time == 0)
                ;
            else if(proc[i].exe_time > rr_time){
                proc[i].exe_time -= rr_time;
                total_time += rr_time;
            }
            else if(proc[i].exe_time>0 && proc[i].exe_time<=rr_time){
                total_time += proc[i].exe_time;
                proc[i].exe_time = 0;
                proc[i].fin_time = total_time;
            }
        }
    }
    qsort(proc, process_num, sizeof(*proc), compare_fin_time);
    for(int i=0; i<process_num; i++){
        printf("%s %d\n", proc[i].name, proc[i].fin_time);
    }
}

