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


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

P Q[LEN];
int head, tail, n;


void initialize(){
    head = tail = 0;
}

int isEmpty() {
    return head==tail;
}

int isFull() {
    return head == (tail + 1) % LEN;
}

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

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


int main(void){
    // Your code here!
    int n, q;
    scanf("%d %d", &n, &q);
    for(int i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    
    initialize();
    head = 1;
    tail = n + 1;
    
    int t;
    int now = 0;
    while(head != tail){
        P x = dequeue();
        t = x.t;
        if(t <= q) {
            now += t;
            printf("%s %d\n", x.name, now);
        } else {
            now += q;
            x.t -= q;
            enqueue(x);
        }
    }
}

