#include<stdio.h>

// NO ERROR handling implemented!! full, empty


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

#define len 100005
p queue[len];

int head, tail, n;// tail always points next empty, head always points NON-null

void enqueue(p x){
    queue[tail]=x;  
    tail=(tail+1)%len;  
}

// 要素得てからhead increしたいときはp xにbuffering
p dequeue(){
    p x=queue[head];
    head=(head+1)%len;
    return x;
}

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

int main(){

    int q;
    p u;
    int elaps=0, c;
    scanf("%d %d",&n, &q);
    for(int i=1;i<=n;i++){  // i==0 remains empty
        scanf("%s", queue[i].name);
        scanf("%d", &queue[i].t );
    }
    head=1;
    tail=n+1;// points to next empty


    while(head!=tail){
        u=dequeue();
        c=min(q,u.t);
        u.t-=c;
        elaps+=c;
        if(u.t>0){
            enqueue(u);
        }else{  // process finished
            printf("%s %d\n", u.name, elaps);
        }
    }



    return 0;
}
