/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: Ivan
 *
 * Created on June 25, 2018, 6:55 PM
 */

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 50001
#define min(a,b) (((a)<(b))?(a):(b))

typedef struct {
    char item[1000];
    int bt;
}Process;

/*
 * 
 */

Process Queue[MAXSIZE];
int head, tail, num_of_item;
void enqueue(Process x);

Process dequeue();

int main(int argc, char** argv) {
    int total_time = 0, time_quantum, needed_time;
    Process current_process;
    
    scanf("%d %d", &num_of_item, &time_quantum);
    
    for (int i = 1; i <= num_of_item; ++i)
        scanf("%s %d", Queue[i].item, &Queue[i].bt);
    
    head = 1; tail = num_of_item + 1;
    
    while (head != tail)
    {
        current_process = dequeue();
        needed_time = min(time_quantum, current_process.bt);
        current_process.bt -= needed_time;
        total_time += needed_time;
        
        if (current_process.bt > 0) enqueue(current_process);
        else { printf("%s %d\n", current_process.item, total_time); }
    }
    return (EXIT_SUCCESS);
}

void enqueue(Process x)
{
    Queue[tail] = x;
    tail = (tail +1) % MAXSIZE;
}

Process dequeue()
{
    Process x = Queue[head];
    head = (head +1) % MAXSIZE;
    return x;
}
