#include<stdio.h>
#define N 100000
typedef struct{
    char name[10];
    int time;
} Process;

Process ps[N];
int head=0;
int tail=0;
int alltime=0;

Process deq(){
    Process res = ps[head];
    if(head + 1 == N){
        head = 0;
    }else {
        head+=1;
    }
    return res;
}

void enq(Process p){
    ps[tail] = p;
    if(tail + 1 == N){
        tail = 0;
    }else {
        tail+=1;
    }
}

void printIt(Process data){
    printf("%s %d\n", data.name, alltime+=data.time);
}


int main(){
    int n, q;
    int i;
    Process data;
    
    scanf("%d%d", &n, &q);
    for(i=0;i<n;i++){
        scanf(" %s%d", data.name, &data.time);
        enq(data);
    }

    while(1){
        if(head == tail) break;
        alltime += q;
        ps[head].time -= q;
        if(ps[head].time <= 0){
            data = deq();
            printIt(data);
        }else {
            data = deq();
            enq(data);
        }
    }

    return 0;

}