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

#define N 100000

typedef struct {
    char name[11];
    int time;
} Process;

Process queue[N];
int top = 0;
int tail = 0;
int num = 0;

void enqueue(char *name, int time) {
    if (tail == N) {
        tail = 0;
    }
    strcpy(queue[tail].name, name);
    queue[tail].time = time;
    tail++;
    num++;
}

Process dequeue() {
    if (top == N) {
        top = 0;
    }
    num--;
    return queue[top++];
}

int main() {
    int p = 0, time, n, q, i, nowtime = 0;
    char name[11];
    Process result[N], tmp;
    
    scanf("%d %d", &n, &q);
    
    for(i = 0; i < n; i++) {
        scanf("%s %d", name, &time);
        enqueue(name, time);
    }
    
    while (num > 0) {
        tmp = dequeue();
        time = tmp.time - q;
        if (time <= 0) {
            strcpy(result[p].name, tmp.name);
            result[p].time = nowtime + tmp.time;
            p++;
            nowtime += tmp.time;
        } else {
            enqueue(tmp.name, time);
            nowtime += q;
        }
    }
    
    for (i = 0; i < p; i++) {
        printf("%s %d\n", result[i].name, result[i].time);
    }
    return 0;
}
