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

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

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

void enqueue(work w){
    Q[tail]=w;
    tail=(tail+1)%LEN;
}

work dequeue(){
    work w=Q[head];
    head=(head+1)%LEN;
    return w;
}

int min(int a,int b){
    return a<b?a:b;
}

int main(){
    int time_sum=0,time_use;
    int i,q;
    work wait_work,working;

    scanf("%d%d",&n,&q);
    for(i=0;i<n;i++){
        scanf("%s",wait_work.name);
        scanf("%d",&wait_work.time);
        enqueue(wait_work);
    }
    while(head!=tail){
       working=dequeue();
       time_use=min(working.time,q);
       time_sum+=time_use;
       working.time-=time_use;
       if(working.time>0){
            enqueue(working);
       }else{
            printf("%s %d\n",working.name,time_sum);
       }
    }
    return 0;
}