#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 100005

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

int head, tail;
P Q[LEN];

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

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

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