#include <stdio.h>

struct process{//プロセス
    char name[10];
    int time;
};



int main(){
    int n,q;//プロセス数n、クオンタムq
    struct process process[1000000];//プロセス
    struct process process_fin[1000000];//完了済みプロセス
    int now_time=0;

    //入力
    scanf("%d %d",&n,&q);
    for(int i=0;i<n;i++){
        scanf("%s %d",&process[i].name,&process[i].time);
    }
    
    int head=0,tail=n;
    int fin_num=0;

    while(head!=tail){
        if(process[head].time>q){//クオンタムより大きい
            now_time += q;
            process[head].time -= q;
            process[tail]=process[head];
            head++;
            tail++;

        }else{//クアンタム以下
            now_time += process[head].time;
            process_fin[fin_num]=process[head];
            process_fin[fin_num].time=now_time;
            head++;
            fin_num++;
        }

        if(head==1000000){
            head=0;
        }
        if(tail==1000000){
            tail=0;
        }
    }

    for(int i=0;i<fin_num;i++){
        printf("%s %d\n",process_fin[i].name,process_fin[i].time);
    }
}
