#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pop{

    char name[100];
    int s;
} POP;

POP Q[LEN];
int head,tail,n;

void enq(POP x){

    Q[tail] = x;
    tail = (tail + 1) % LEN;

}

POP deq(){

    POP x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a,int b){

    if(a<b)
    return a;

    else
    return b;
}

int main(){

    int laps = 0;
    int i,a,q;
    POP r;

    scanf("%d %d",&n,&q);

    for(i=1;i<=n;i++){

        scanf("%s",Q[i].name);
        scanf("%d"Q[i].s);
    }

    head = 1;
    tail = n + 1;

    while(head != tail){

        r = deq();
        a = min(q,r.s);

        r.s -= a;
        laps += a;

        if(r.s>0)
        enq(r);

        else{
            printf("%s %d\n",r.name,laps);
        }

    }
    return 0;
}
