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

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	}	
}


/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