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

#define MAX 100000

typedef struct{
    char name[10];
    int time;
}   PROCESS;

int isEmpty(PROCESS *);
int isFull(PROCESS *);
void enqueue(PROCESS *, PROCESS);
PROCESS dequeue(PROCESS *);
void rrs(PROCESS *, int);

int head=0, tail=0;

int main(){
    int n, q, a, total_time=0, count=0;
    PROCESS p[MAX], process;
    
    scanf("%d%d",&n,&q);
    for(a = 0; a < n; a++){
        scanf("%s%d",process.name,&process.time);
        if(process.time > q){
            total_time += q;
            process.time -= q;
            enqueue(p,process);
            count++;
        }
        else{
            total_time += process.time;
            printf("%s %d\n",process.name,total_time);
        }
    }

    while(1){
        process = dequeue(p);
        if(process.time == -1) break;
        else if(process.time > q){
            total_time += q;
            process.time -= q;
            enqueue(p,process);
        }
        else{
            total_time += process.time;
            printf("%s %d\n",process.name,total_time);
        }
    }


    return 0;
}

int isEmpty(PROCESS *p){
    if(head == tail) return 1;
    else return 0;
}

int isFull(PROCESS *p){
    if(head == (tail+1) % MAX) return 1;
    else return 0;
}

void enqueue(PROCESS *p, PROCESS x){
    if(isFull(p) == 1) exit(1);
    p[tail] = x;
    if((tail+1) == MAX) tail = 0;
    else tail++;
}

PROCESS dequeue(PROCESS *p){
    PROCESS x;
    if(isEmpty(p) == 1){
        x.time = -1;
        return x;
    }
    x = p[head];
    if((head+1) == MAX) head = 0;
    else head++;
    return x;
}

