import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	public static void runSchedule(Queue<String[]> tasks, int quantum) {
		int totalTime = 0;
		
		while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		}
		
		
	}
	

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int nTasks = scan.nextInt();
		int quantum = scan.nextInt();
		scan.nextLine();
		
		Queue<String[]> tasks = new ArrayDeque<>();
		
		for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		}
		scan.close();
		
		runSchedule(tasks, quantum);
	}

}


/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