import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

// You cant store primitive types in queue?

public class Main{
    public static void main(String[] args) {
        Queue<String> q = new LinkedList<>();

        Scanner input1 = new Scanner(System.in);
        int length = input1.nextInt();
        int QUANTUM = input1.nextInt();
        int totalTime=0;
        int result; // This is the time of each item
        String name;

        input1.nextLine();
        // Takes all the inputs and put into the queue
        for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        }

        while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        }
    }
}


/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz