#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 100010
#define pi M_PI

typedef struct ppp{
    char name[20];
    int time;
} P;

P Q[N];
int head=0,tail=0;

void enqueue(P x){
    Q[tail]=x;
    tail =(tail+1)%N;
}
P dequeue(){
    P x=Q[head];
    head =(head+1)%N;
    return x;
}
int main(){
    int n,q;
    scanf("%d%d\n",&n,&q);
    int result=0;
    for(int i=0;i<n;i++){
        P qu;
        scanf("%s%d",qu.name,&qu.time);
        enqueue(qu);
    }
    while(head != tail){
        P kari = dequeue();
        if(kari.time<=q){
            result += kari.time;
            printf("%s %d\n",kari.name,result);
        }else{
            result += q;
            kari.time -= q;
            enqueue(kari);
        }
    }
    return 0;
}

