#include <stdio.h>
#include <assert.h>

#define N 100000
typedef struct{
   char name[10];
   int time;
} Data;

typedef struct{
    int head,tail;
    Data data[N];
}Queue;


int empty(Queue *);
void push(Queue *,Data);
Data pop(Queue *);


int main(){
    int num,sec,sum=0;
    int i,j;
    Data data;
    Queue que;
   
   scanf("%d%d",&num,&sec);
   for(i=0;i<num;i++){
       scanf("%s %d",data.name,&data.time);
       push(&que,data);
    }

    while(empty(&que) != 1){
        data = pop(&que);
        data.time = data.time - sec;
        if(data.time > 0){
            sum += sec;
            push(&que,data);  
        }
        else{
            sum += data.time + sec;
            printf("%s %d\n",data.name,sum);
        }
        
     }
     return 0;
}



int empty(Queue *q){
    return (q->head == q->tail);
}

void push(Queue *q,Data d){
    q->data[(q->tail++)%N] = d; 
}

Data pop(Queue *q){

    return q->data[(q->head++)%N];
}
  

