#include <stdio.h>
#include <stdlib.h>

struct q{
    char name[10];
    int t;
    struct q *next;
    struct q *prev;
};

typedef struct q * Q;

void enqueue(Q);
void dequeue();
void moveBack();
void printstate();

Q head;

int main(){
    
    int i, n, qt, time = 0;
    Q x;
    
    head = malloc(sizeof(struct q));
    head->next = head;
    head->prev = head;
    
    //input
    scanf("%d%d",&n,&qt);
    
    for (i = 0; i < n; i++){
        x = malloc(sizeof(struct q));
        scanf("%s", x->name);
        scanf("%d", &x->t);
        enqueue(x);
    }
    
  //process
    while(head->prev != head){
        if((head->next)->t > qt){
            (head->next)->t -= qt;
            moveBack();
            time += qt;
        }
        
        else{
            time += (head->next)->t;
            printf("%s %d\n",(head->next)->name, time);
            dequeue();
        }
        
        //printstate();
    }
    free(head);
    
    return 0;
}

    void enqueue(Q x){
        x->next = head;
        x->prev = head->prev;
        head->prev = x;
        (x->prev)->next = x;
    }
    
    void dequeue(){
        Q d = head->next, x = (head->next)->next;
        head->next = x;
        x->prev = head;
        
        free(d);
    }

    void moveBack(){
        Q x = (head->next)->next;
        if(x != head){
            enqueue(head->next);
            head->next = x;
            x->prev = head;
        }
    }

void printstate(){
    int i;
    Q x = head;
    
    for(i = 0; i < 5; i++){
        printf("%s %d\n",x->name,x->t);
        x=x->next;
    }
    
}

