#include<stdio.h>
#define LENGTH 100000

typedef struct pp{
    char name[100];
    int time;
} P;

int head, tail;
P Q[LENGTH];

void enqueue(P x){
    Q[tail] = x;
    tail = (tail+1) % LENGTH;
}

P dequeue(){
    P x = Q[head];
    head = (head+1) % LENGTH;
    return x;
}

int min(int a, int b){
    if(a <= b){
        return a;
    }
    else{
        return b;
    }
}

int main(void){
    int N;
    int q;
    scanf("%d %d",&N, &q);
    head = 0;
    tail = N;
    for(int i = 0; i < N; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].time);
    }
    P u;
    int elaps = 0, c;
    while(head != tail){
        u = dequeue();
        c = min(q, u.time);
        elaps += c;
        u.time -= c;
        if(u.time > 0){
            enqueue(u);
        }
        else{
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}
