#include <cstdio>

int head, tail;
#define len 100010
typedef struct pp {
    char name[20];
    int time;
} P;
P Q[len];

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail+1)%len;
}
P dequeue() {
    P x = Q[head];
    head = (head+1)%len;
    return x;
}
int min(int a, int b) {return a<b?a:b;}

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int n, q, last = 0;
    scanf("%d%d", &n, &q);
    for(int i=0; i<n; ++i)
        scanf("%s%d", Q[i].name, &Q[i].time);

    head = 0, tail = n;
    while(head != tail) {
        P u = dequeue();
        int x = min(q, u.time);
        u.time -= x; last += x;
        if(u.time) enqueue(u);
        else printf("%s %d\n", u.name, last);
    } 

    return 0;
}
