#include<stdio.h>
#include<stdlib.h>
typedef struct{
        char name[11];
        int time;
}process;
typedef struct node{
        process data;
        struct node *next;
        struct node *prev;
}queue;
queue *head = NULL;
queue *last = NULL;
void Push_back(process);
process Pop_front(void);
main()
{
        int n, q, count = 0;
        process pro;
        scanf("%d %d%*c", &n, &q);
                while(n--){
                        scanf("%s %d%*c", pro.name, &pro.time);
                        Push_back(pro);
                }
                while(last != NULL){
                        pro = Pop_front();
                        if(pro.time > q){
                                pro.time -= q;
                                Push_back(pro);
                                count += q;
                        }else{
                                count += pro.time;
                                printf("%s %d\n", pro.name, count);
                        }
                }
}
void Push_back(process data)
{
        queue *p;
        if((p = (queue*)malloc(sizeof(process))) == NULL){
                fprintf(stderr, "Memory cannot allocate\n");
                exit(0);
        }
        p -> data = data;
        p -> next = NULL;
        p -> prev = last;
        last = p;
        if(head == NULL){
                head = p;
        }else{
                        p -> prev -> next = p;
                }
}
process Pop_front(void)
{
        process pop_data;
        queue *p = head;
        if(last == NULL){
                        exit(1);
        }
        pop_data = head -> data;
        if(head -> next== NULL){
                last = NULL;
        }else{
                head -> next -> prev = NULL;
        }
        p = head;
                head = head -> next;
        //free(p);
        return pop_data;
}