/*
 * FileName:     queue_fix_2
 * CreatedDate:  2020-04-16 00:49:20 +0900
 * LastModified: 2020-04-16 01:48:27 +0900
 */

#include <stdio.h>
#include <stdlib.h>
typedef struct _node{
    char name[10];
    int time;
    struct _node *prev;
    struct _node *next;
    
}node;

int main(void){
    int n,q;
    scanf("%d %d",&n,&q);
    node *queue=(node*)calloc(n,sizeof(node));
    scanf("%s %d",queue->name,&queue->time);
    queue->prev=queue+n-1;
    for(int i=1;i<n;i++){
        scanf("%s %d",queue[i].name,&queue[i].time);
        queue[i].prev=queue+i-1;
        queue[i-1].next=queue+i;
    }
//    printf("%s,%d\n",queue[0].name,queue[0].time);
    queue[n-1].next=queue;
    node *head=queue,*tail=&queue[n-1];
//    printf("%s,%d\n",head->name,head->time);
    int tmp=0;
    while(head!=tail){
        if(head->time<=q){
            printf("%s %d\n",head->name,head->time+tmp);
            tmp+=head->time;
            head->prev->next=head->next;
            head->next->prev=head->prev;
            
            head=head->next;

        }
        else{
            tmp+=q;
            head->time-=q;
            head=head->next;
            tail=tail->next;
        }
    }
    printf("%s %d\n",head->name,head->time+tmp);
    free(queue);
    return 0;
}

