#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>
#define PROCESS_MAX 100001
  
typedef struct{
    char          name[11];
    uint_fast32_t time    ;
} s_process;
  
int main(void)
{
    uint_fast32_t n, q, head = 0, tail = 0, process_time = 0;
    s_process process[PROCESS_MAX];
  
    scanf("%"SCNu32" %"SCNu32, &n, &q);
    for(uint_fast32_t i=0; i<n; ++i){
        scanf("%s %"SCNu32, process[i].name, &process[i].time);
    }
    tail = n;
  
    while(head != tail){
        if(process[head].time > q){
            process_time       += q            ;
            process[head].time -= q            ;
            process[tail]       = process[head];
            head = (head+1) % PROCESS_MAX;
            tail = (tail+1) % PROCESS_MAX;
        }else{
            process_time += process[head].time;
            printf("%s %"PRIu32"\n", process[head].name, process_time);
            head = (head+1) % PROCESS_MAX;
        }
    }
  
    return 0;
}

