
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scin = new Scanner(System.in);
		String[] baseInput = scin.nextLine().split(" ");
		
		int numberOfProcesses = Integer.parseInt(baseInput[0]);
		int timeSlotLength = Integer.parseInt(baseInput[1]);
		
		Queue<String> queue = new LinkedList<>();
		
		for (int i = 0; i < numberOfProcesses; i++) {
			queue.add(scin.nextLine());
		}
		
		//now run it
		Queue<String> finished = new LinkedList<>();
		int totalElapsedTime = 0;
		
		while (queue.isEmpty() == false) {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		}
		
		while (finished.isEmpty() == false) {
			System.out.println(finished.remove());
		}
	}
}
 import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner scin = new Scanner(System.in);
		String[] baseInput = scin.nextLine().split(" ");
		
		int numberOfProcesses = Integer.parseInt(baseInput[0]);
		int timeSlotLength = Integer.parseInt(baseInput[1]);
		
		Queue<String> queue = new LinkedList<>();
		
		for (int i = 0; i < numberOfProcesses; i++) {
			queue.add(scin.nextLine());
		}
		
		//now run it
		Queue<String> finished = new LinkedList<>();
		int totalElapsedTime = 0;
		
		while (queue.isEmpty() == false) {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		}
		
		while (finished.isEmpty() == false) {
			System.out.println(finished.remove());
		}
	}
} Main public static void main(String[] args) {
		Scanner scin = new Scanner(System.in);
		String[] baseInput = scin.nextLine().split(" ");
		
		int numberOfProcesses = Integer.parseInt(baseInput[0]);
		int timeSlotLength = Integer.parseInt(baseInput[1]);
		
		Queue<String> queue = new LinkedList<>();
		
		for (int i = 0; i < numberOfProcesses; i++) {
			queue.add(scin.nextLine());
		}
		
		//now run it
		Queue<String> finished = new LinkedList<>();
		int totalElapsedTime = 0;
		
		while (queue.isEmpty() == false) {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		}
		
		while (finished.isEmpty() == false) {
			System.out.println(finished.remove());
		}
	} main {
		Scanner scin = new Scanner(System.in);
		String[] baseInput = scin.nextLine().split(" ");
		
		int numberOfProcesses = Integer.parseInt(baseInput[0]);
		int timeSlotLength = Integer.parseInt(baseInput[1]);
		
		Queue<String> queue = new LinkedList<>();
		
		for (int i = 0; i < numberOfProcesses; i++) {
			queue.add(scin.nextLine());
		}
		
		//now run it
		Queue<String> finished = new LinkedList<>();
		int totalElapsedTime = 0;
		
		while (queue.isEmpty() == false) {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		}
		
		while (finished.isEmpty() == false) {
			System.out.println(finished.remove());
		}
	} Scanner scin = new Scanner(System.in); scin new Scanner(System.in) String[] baseInput = scin.nextLine().split(" "); baseInput scin.nextLine().split(" ") scin.nextLine().split scin.nextLine() scin.nextLine scin " " int numberOfProcesses = Integer.parseInt(baseInput[0]); numberOfProcesses Integer.parseInt(baseInput[0]) Integer.parseInt Integer baseInput[0] baseInput 0 int timeSlotLength = Integer.parseInt(baseInput[1]); timeSlotLength Integer.parseInt(baseInput[1]) Integer.parseInt Integer baseInput[1] baseInput 1 Queue<String> queue = new LinkedList<>(); queue new LinkedList<>() for (int i = 0; i < numberOfProcesses; i++) {
			queue.add(scin.nextLine());
		} int i = 0; int i = 0; i 0 i < numberOfProcesses i numberOfProcesses i++ i++ i {
			queue.add(scin.nextLine());
		} {
			queue.add(scin.nextLine());
		} queue.add(scin.nextLine()) queue.add queue scin.nextLine() scin.nextLine scin Queue<String> finished = new LinkedList<>(); finished new LinkedList<>() int totalElapsedTime = 0; totalElapsedTime 0 while (queue.isEmpty() == false) {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		} queue.isEmpty() == false queue.isEmpty() queue.isEmpty queue false {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		} String[] rawParts = queue.remove().split(" "); rawParts queue.remove().split(" ") queue.remove().split queue.remove() queue.remove queue " " int durrationLeft = Integer.parseInt(rawParts[1]); durrationLeft Integer.parseInt(rawParts[1]) Integer.parseInt Integer rawParts[1] rawParts 1 String name = rawParts[0]; name rawParts[0] rawParts 0 if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			} durrationLeft <= timeSlotLength durrationLeft timeSlotLength {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			} finished.add(name + " " +(totalElapsedTime + durrationLeft)) finished.add finished name + " " +(totalElapsedTime + durrationLeft) name + " " +(totalElapsedTime + durrationLeft) name " " (totalElapsedTime + durrationLeft) totalElapsedTime durrationLeft totalElapsedTime += durrationLeft totalElapsedTime durrationLeft {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			} durrationLeft -= timeSlotLength durrationLeft timeSlotLength totalElapsedTime += timeSlotLength totalElapsedTime timeSlotLength queue.add(name + " " +durrationLeft) queue.add queue name + " " +durrationLeft name + " " +durrationLeft name " " durrationLeft while (finished.isEmpty() == false) {
			System.out.println(finished.remove());
		} finished.isEmpty() == false finished.isEmpty() finished.isEmpty finished false {
			System.out.println(finished.remove());
		} System.out.println(finished.remove()) System.out.println System.out System System.out finished.remove() finished.remove finished String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scin = new Scanner(System.in);
		String[] baseInput = scin.nextLine().split(" ");
		
		int numberOfProcesses = Integer.parseInt(baseInput[0]);
		int timeSlotLength = Integer.parseInt(baseInput[1]);
		
		Queue<String> queue = new LinkedList<>();
		
		for (int i = 0; i < numberOfProcesses; i++) {
			queue.add(scin.nextLine());
		}
		
		//now run it
		Queue<String> finished = new LinkedList<>();
		int totalElapsedTime = 0;
		
		while (queue.isEmpty() == false) {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		}
		
		while (finished.isEmpty() == false) {
			System.out.println(finished.remove());
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scin = new Scanner(System.in);
		String[] baseInput = scin.nextLine().split(" ");
		
		int numberOfProcesses = Integer.parseInt(baseInput[0]);
		int timeSlotLength = Integer.parseInt(baseInput[1]);
		
		Queue<String> queue = new LinkedList<>();
		
		for (int i = 0; i < numberOfProcesses; i++) {
			queue.add(scin.nextLine());
		}
		
		//now run it
		Queue<String> finished = new LinkedList<>();
		int totalElapsedTime = 0;
		
		while (queue.isEmpty() == false) {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		}
		
		while (finished.isEmpty() == false) {
			System.out.println(finished.remove());
		}
	}
} Main

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scin = new Scanner(System.in);
		String[] baseInput = scin.nextLine().split(" ");
		
		int numberOfProcesses = Integer.parseInt(baseInput[0]);
		int timeSlotLength = Integer.parseInt(baseInput[1]);
		
		Queue<String> queue = new LinkedList<>();
		
		for (int i = 0; i < numberOfProcesses; i++) {
			queue.add(scin.nextLine());
		}
		
		//now run it
		Queue<String> finished = new LinkedList<>();
		int totalElapsedTime = 0;
		
		while (queue.isEmpty() == false) {
			String[] rawParts = queue.remove().split(" ");
			int durrationLeft = Integer.parseInt(rawParts[1]);
			String name = rawParts[0];
			
			if (durrationLeft <= timeSlotLength) {
				finished.add(name + " " +(totalElapsedTime + durrationLeft));
				totalElapsedTime += durrationLeft;
			}else {
				durrationLeft -= timeSlotLength;
				
				totalElapsedTime += timeSlotLength;
				
				queue.add(name + " " +durrationLeft);
			}
		}
		
		while (finished.isEmpty() == false) {
			System.out.println(finished.remove());
		}
	}
}

