#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define LEN 100005
typedef struct a{
    char name[100];
    int time;
}Q;
int head;
int tail;
Q A[LEN];

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

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

int min(int a ,int  b){
    return a < b ? a : b;
}

int main(){
    int i, n,q, minn;
    int timer = 0;
    Q x;

    scanf("%d %d", &n, &q);
    head = 0; tail = n;
    for(i = 0; i < n; i++){
        scanf("%s %d", A[i].name, &A[i].time);
    }

    while(head != tail){
        x = denqueue();
        minn = min(x.time, q);
        x.time -= minn;
        timer += minn;
        if(x.time <= 0){
            printf("%s %d\n", x.name, timer);
        }else{
            enqueue(x);
        }
    }
    return 0;
}
