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

public class Main {
	
	public static void main(String[] args) {
		
		int numberOfProcesses;
		int quantum;
		int clock = 0;
		String line;
		
		Queue<String> taskQueue = new LinkedList<String>();
		Queue<Integer> timeQueue = new LinkedList<Integer>();
		
		Scanner keyboard = new Scanner(System.in);
		Scanner input;
		
		line = keyboard.nextLine();
		
		input = new Scanner(line);
		
		numberOfProcesses = Integer.parseInt(input.next());
		quantum = Integer.parseInt(input.next());
		
		for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		}
		
		while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		}
		
		
		
	}

}

/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