#include<stdio.h>
#define MAX 100005

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

int head , tail, n;
P queue[MAX];
void enqueue(P x)
{
    queue[tail] = x;
    tail = ( tail + 1 ) % MAX;
}

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


int main()
{
    int q, i, tmp, time = 0;
    P u;
    scanf("%d %d", &n, &q);
    for( i = 0; i < n; i++ ){
        scanf("%s%d", queue[i].name, &queue[i].t);
    }
    head = 0; tail = n;
    while( head != tail ){
        u = dequeue();
        if( u.t > q ){
            time += q;
            u.t -= q;
            enqueue(u);
        }else{
            time += u.t;
            printf("%s %d\n", u.name, time);
        }
    }
    return 0;
}