#include<stdio.h>
#define N 100000

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

Process dequeue(Process *q, int *n, int *alltime){
    Process res = q[0];
    int i;

    for(i=0;i<*n-1;i++){
        q[i] = q[i+1];
    }
    *n = *n - 1;
    res.finish_time = *alltime + res.time;
    return res;
}

void enqueue(Process in, Process *q, int *n){
    q[*n] = in;
    (*n)++;
}

void printIt(Process p){
    printf("%s %d\n", p.name, p.finish_time);
}

int main(){
    int n, q;
    Process procs[N], data;
    int i, alltime=0;
    scanf("%d%d", &n, &q);
    for(i=0;i<n;i++) scanf(" %s%d", procs[i].name, &procs[i].time);

    while(1){
        if(n<=0) break;
        procs[0].time -= q;
        alltime += q;
        if(procs[0].time <= 0){
            data = dequeue(procs, &n, &alltime);
            alltime += data.time;
            printIt(data);
        }else {
            data = dequeue(procs, &n, &alltime);
            enqueue(data, procs, &n);
        }
    }
    return 0;
}