#include <stdio.h>
#include <stdlib.h>
#define N 100001
typedef struct {
    char a[10];
    int t;
}record;

record queue[N];
int head, tail;
void enQueue(record x){
    queue[tail] = x;
    tail = (tail+1)%N;
}
record deQueue(){
    record p = queue[head];
    head = (head+1)%N;
    return p;
}

int main(){
    int n, cmp;
    scanf("%d %d", &n, &cmp);
    for(int i = 0; i < n; i++){
        scanf("%s %d", queue[i].a, &queue[i].t);
    }

    head = 0, tail = n;
    int now = 0;
    while(head != tail){
        record top = deQueue();
        if(top.t <= cmp){
            now += top.t;
            printf("%s %d\n", top.a, now);
        }
        else{
            now += cmp;
            top.t -= cmp;
            enQueue(top);
        }
    }
    return 0;
}
