#include <stdio.h>
#include <string.h>
#define LEN 100005
#define min(a,b) ((a)<(b)?(a):(b))


typedef struct {
    char name[100];
    int time;
} CPU;

CPU Queue[LEN];
int head,tail,n;

void enqueue(CPU x) {
    Queue[tail]=x;
    tail=(tail+1)%LEN;
}
CPU dequeue() {
    CPU x=Queue[head];
    head=(head+1)%LEN;
    return x;
}
int main() {
    int el=0,c,i,q;
    CPU u;
    scanf("%d %d",&n,&q);
    for (i=1; i<=n; i++) {
        scanf("%s",Queue[i].name);
        scanf("%d",&Queue[i].time);
    }
    head=1; tail=n+1;
    while (head!=tail) {
        u=dequeue();
        c=min(q,u.time);
        u.time-=c;
        el+=c;
        if (u.time>0) {
            enqueue(u);
        } else {
            printf("%s %d\n",u.name,el);
        }
    }
}
