#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE_OF_NAME 11
#define QUEUE_SIZE 100000

typedef struct{
    char name[SIZE_OF_NAME];
    int time;
}Quantum;

typedef struct{
    int front;
    int back;
    int size;
    int max;
}Queue;

void printQuantum(Quantum, int);
void queueInit(Queue*);
void setMax(Queue*, int);
void enqueue(Queue*);
void dequeue(Queue*, Quantum*);
Quantum front(Queue*, Quantum*);
int isFull(Queue*);
int isEmpty(Queue*);

int main(int argc, char** argv) {
    int size, interval;
    int timeLapsed = 0;
    Quantum temp;
    scanf("%d %d", &size, &interval);
    Quantum arrayQ[size];
    
    Queue arrayQl;
    queueInit(&arrayQl);
    setMax(&arrayQl, size);
    for(int i = 0; i < size; i++){
        scanf("\n%s %d", arrayQ[i].name, &arrayQ[i].time);
        enqueue(&arrayQl);
    }
    while(!isEmpty(&arrayQl)){
        if(front(&arrayQl,arrayQ).time - interval > 0){
            timeLapsed += interval;
            temp = front(&arrayQl,arrayQ);
            dequeue(&arrayQl,arrayQ);
            strcpy(arrayQ[arrayQl.back].name, temp.name);
            arrayQ[arrayQl.back].time = temp.time - interval;
            enqueue(&arrayQl);
        }
        else{
            timeLapsed += front(&arrayQl,arrayQ).time;
            printQuantum(front(&arrayQl,arrayQ), timeLapsed);
            dequeue(&arrayQl,arrayQ);
        }
    }
    
    return (EXIT_SUCCESS);
}

void printQuantum(Quantum q, int time){
    printf("%s %d\n",q.name, time);
}

void queueInit(Queue *ql){
    ql->size = 0;
    ql->front = 0;
    ql->back = 0;
}

void setMax(Queue *ql, int max){
    ql->max = max;
}

void enqueue(Queue *ql){
    if(!isFull(ql)){
        ql->back++;
        ql->size++;
        ql->back %= ql->max;
    }
    if(ql->size == ql->max)
        ql->back = -1;
}

void dequeue(Queue *ql, Quantum *q){
    strcpy(q[ql->front].name,"");
    q[ql->front++].time = 0;
    ql->size--;
    ql->front %= ql->max;
    if(ql->back == -1){
        if(ql->front == 0)
            ql->back = ql->max - 1;
        else
            ql->back = ql->front - 1;
    }
}

Quantum front(Queue *ql, Quantum *q){
    return q[ql->front];
}

int isFull(Queue *ql){
    if(ql->size < ql->max) return 0;
    return 1;
}

int isEmpty(Queue *ql){
    if(ql->size == 0) return 1;
    return 0;
}

