#include<stdio.h>

typedef struct{
        char name[11];
        int t;
}Pro;

#define len 100005

int main(){
        int total=0, q, i, n;
        scanf("%d %d", &n, &q);
        Pro pro[len];
        int max=n;

        for(i=0; i<n; i++){
                scanf("%s %d", pro[i].name, &pro[i].t);
        }

        int front=0, rear=n;
        do{
                if((pro[front].t-q)<=0){
                        total+=pro[front].t;
                        printf("%s %d\n", pro[front].name, total);
                        front=(front+1)%len;
                        max--;
                }else{
                        total+=q;
                        pro[front].t-=q;
                        pro[rear]=pro[front];
                        front=(front+1)%len; rear=(rear+1)%len;
                }
        }while(max!=0);

        return 0;
}

