#include <stdio.h>

typedef struct{
    char name[11];
    int t;
    int prev;
    int next;
}QUEUE;

int main(void){
    int i;
    
    int n,q;
    scanf("%d %d",&n,&q);
    
    QUEUE Q[n];
    for(i=0;i<n;i++){
        scanf("%s %d",Q[i].name,&Q[i].t);
        if(i==0)Q[i].prev=n-1;
        else Q[i].prev=i-1;
        if(i==n-1)Q[i].next=0;
        else Q[i].next=i+1;
    }
    
    int count=0;
    i=0;
    int tmp,k=0;
    while(i!=-1&&k!=n){
        if(Q[i].t<=q){
            count=count+Q[i].t;
            printf("%s %d\n",Q[i].name,count);
            tmp=i;
            i=Q[tmp].next;
            Q[tmp].t=0;
            Q[Q[tmp].prev].next=Q[tmp].next;
            Q[Q[tmp].next].prev=Q[tmp].prev;
            Q[tmp].next=-1;
            Q[tmp].prev=-1;
            k++;
        }else{
            count=count+q;
            Q[i].t=Q[i].t-q;
            i=Q[i].next;
        }
    }
}

