#include <stdio.h>
#define N 100000

typedef struct process{
    char name[100];
    int t;
    int next;
    int prev;
} process_t;

    process_t proc[N];

int main(void) {
    int i;
    int n, q;
    int total; 
    int pnt;
    int cnt;

    scanf("%d", &n);
    scanf("%d", &q);

    for(i=0; i<n; i++){
        proc[i].next = i+1;
        proc[i].prev = i-1;
        scanf("%s", proc[i].name);
        scanf("%d", &proc[i].t);
    }

    proc[n-1].next = 0;
    proc[0].prev = n-1;

    total = 0;
    pnt = 0;
    cnt = n;

    while(cnt > 0){
        if(proc[pnt].t > q) {
            proc[pnt].t -= q;
            total += q;
            pnt = proc[pnt].next;
        }
        
        else {
            total += proc[pnt].t;
            printf("%s %d\n", proc[pnt].name, total);
            proc[proc[pnt].prev].next = proc[pnt].next;
            proc[proc[pnt].next].prev = proc[pnt].prev;
            pnt = proc[pnt].next;
            cnt--;            
        }
    }

    return 0;
}
