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

typedef struct {
    char name[100];
    int time;
}Proces;
int head=0;tail=0;
Proces que[LEN];
void enqueue(Proces);
Proces dequeue();
int min(int,int);
void enqueue(Proces x){
    que[tail]=x;
    tail=(tail+1)%LEN;
    return;
}
Proces dequeue(){
    Proces x=que[head];
    head=(head+1)%LEN;
    return x;
}
int min(int x,int y){
    return x < y ? x : y;
}
int main(void){
    int i,n,q,c,sum=0;
    Proces a;
    scanf("%d %d",&n,&q);
    for(i=0;i<n;i++){
        scanf("%s %d",que[i].name,&que[i].time);
    }
    head=0;tail=n;
    while(head!=tail){
        a=dequeue();
        c=min(q,a.time);
        a.time-=c;
        sum+=c;
        if(a.time>0){
            enqueue(a);
        }else{
            printf("%s %d\n",a.name,sum);
        }
    }
    return 0;
}

