#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define N 100000

typedef struct{
    char name[10];
    int time;
}Process;

Process *head,*tail;
Process *proc;

void enqueue(Process x,int n){
    if((head==&proc[0]&&tail==&proc[n-1])||(tail+1==head)) //full
        return;
    *tail=x;
    if(tail==&proc[n-1])
        tail=proc;
    else
        tail++;
    return;
}

Process dequeue(int n){
    Process p={"empty",0};
    if(head==tail)
        return p;
    p=(*head);
    if(head==&proc[n-1])
        head=proc;
    else
        head++;
    return p;
}


int main(){
    int num,q,sum_time=0;
    Process ret;

    scanf("%d%d",&num,&q);
    num++;
    proc=(Process*)malloc(sizeof(Process)*num);
    head=proc;
    tail=&proc[num-1];

    for(int i=0;i<num-1;i++){
        scanf("%s%d",&proc[i].name,&proc[i].time);
    }

    while(true){
        ret=dequeue(num);
        if(strcmp(ret.name,"empty")==0)
            break;
        if(ret.time-q<=0){
            sum_time+=ret.time;
            printf("%s %d\n",ret.name,sum_time);
           continue;
        }
        else{
            ret.time=ret.time-q;
            enqueue(ret,num);
            sum_time+=q;
        }
    }

    /*for(int j=0;;j++){
        ret=dequeue(num);
        if(strcmp(ret.name,"empty")==0)
            break;
        printf("%s %d\n",ret.name,ret.time);
    }*/

    free(proc);
    return 0;

}

