#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 100005

int head, tail;

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

P Q[MAX+1];

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

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

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

int enqueue(P x){
    if (isFull()){
        printf("Overflow\n");
        exit(1);
    }else{
        Q[tail] = x;
        tail = (tail + 1) % MAX;
        return 1; 
    }
}

P dequeue(void){
    if (isEmpty()){
        printf("Underflow\n");
        exit(1);
    }else{
        P x = Q[head];
        head = (head + 1) % MAX;
        return x;
    }
}

void rrs(int n, int quantum){
    P finished, tmp;
    int fincnt = 0;
    int now = 0;
    while (fincnt < n){
        now += (Q[head].time - quantum > 0)?(quantum):(Q[head].time);
        Q[head].time = (Q[head].time - quantum > 0)?(Q[head].time - quantum):(0);
        if (Q[head].time == 0){
            finished = dequeue();
            printf("%s %d\n", finished.name, now);
            fincnt++;
        }else{
            tmp = dequeue();
            enqueue(tmp);
        }
    }

}

int main(void){
    int n;
    int quantum;
    int i;
    P tmp;

    initialize();
    
    scanf("%d %d", &n, &quantum);
    for (i = 0; i < n; i++){
        scanf(" %s %d", tmp.name, &tmp.time);
        enqueue(tmp);
    }
    rrs(n, quantum);
    return 0;
}