#include<stdio.h>

#define N 100000

typedef struct{
    char name[11];
    int time_process;
    int time_count;
} queue_in;
void enqueue(queue_in data1);
void dequeue(queue_in data2);
queue_in A[N],B[N],tmp;
int first = 0;
int n;

int main(){
    int q,i,j,tmp_sort,k=0,count=0,tmp_i,flag;
    queue_in sortfor;
    scanf("%d%d",&n,&q);
    tmp_sort = n;
    for(i=0;i<n;i++){
        scanf("%s%d",A[i].name,&A[i].time_process);
    }
    while(n>0){
        if((A[first].time_process -q) <=0){
            A[first].time_count = (A[first].time_process) + count;
            count += A[first].time_process;
            B[k] = A[first];
            k++;
            dequeue(A[first]);
            continue;
        }
        A[first].time_process -= q;
        count += q;
        dequeue(A[first]);
        enqueue(tmp);
    }
    for(i=0;i<tmp_sort;i++){
        tmp_i = i;
        flag = 0;
        for(j=i;j<n;j++){
            if(B[j].time_count<B[tmp_i].time_count){
                tmp_i = j;
                flag = 1;
            }
        }
        if(flag==1){
            sortfor = B[i];
            B[i] = B[tmp_i];
            B[tmp_i] = sortfor;
        }
    }
    for(i=0;i<tmp_sort;i++){
        printf("%s %d\n",B[i].name,B[i].time_count);
    }
}

void enqueue(queue_in data1){
    if(n<N){
        A[(first+n) % N] = data1;
        n++;
    }
}
void dequeue(queue_in data2){
    if(n>0){
        tmp = data2;
        first = (first+1) % N;
        n--;
    }
}
