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

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		LinkedList<String> processes = new LinkedList<>();
		int numProcesses = scanner.nextInt();
		int quantum = scanner.nextInt();
		int timestamp = 0;
		String result = "";
		//get all processes from scanner
		scanner.nextLine();
		for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		}
		scanner.close();
		
		while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		}
	}
} import java.util.Scanner; Scanner java.util import java.util.LinkedList; LinkedList java.util public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		LinkedList<String> processes = new LinkedList<>();
		int numProcesses = scanner.nextInt();
		int quantum = scanner.nextInt();
		int timestamp = 0;
		String result = "";
		//get all processes from scanner
		scanner.nextLine();
		for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		}
		scanner.close();
		
		while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		LinkedList<String> processes = new LinkedList<>();
		int numProcesses = scanner.nextInt();
		int quantum = scanner.nextInt();
		int timestamp = 0;
		String result = "";
		//get all processes from scanner
		scanner.nextLine();
		for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		}
		scanner.close();
		
		while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		LinkedList<String> processes = new LinkedList<>();
		int numProcesses = scanner.nextInt();
		int quantum = scanner.nextInt();
		int timestamp = 0;
		String result = "";
		//get all processes from scanner
		scanner.nextLine();
		for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		}
		scanner.close();
		
		while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) LinkedList<String> processes = new LinkedList<>(); processes new LinkedList<>() int numProcesses = scanner.nextInt(); numProcesses scanner.nextInt() scanner.nextInt scanner int quantum = scanner.nextInt(); quantum scanner.nextInt() scanner.nextInt scanner int timestamp = 0; timestamp 0 String result = ""; result "" scanner.nextLine() scanner.nextLine scanner for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		} int i = 0; int i = 0; i 0 i < numProcesses i numProcesses i++ i++ i {
			processes.add(scanner.nextLine());
		} {
			processes.add(scanner.nextLine());
		} processes.add(scanner.nextLine()) processes.add processes scanner.nextLine() scanner.nextLine scanner scanner.close() scanner.close scanner while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		} !processes.isEmpty() processes.isEmpty() processes.isEmpty processes {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		} String[] process = processes.remove().split(" "); process processes.remove().split(" ") processes.remove().split processes.remove() processes.remove processes " " String name = process[0]; name process[0] process 0 int timeLeft = Integer.parseInt(process[1]); timeLeft Integer.parseInt(process[1]) Integer.parseInt Integer process[1] process 1 if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			} timeLeft-quantum > 0 timeLeft-quantum timeLeft quantum 0 {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			} processes.add(name + " " + (timeLeft-quantum)) processes.add processes name + " " + (timeLeft-quantum) name + " " + (timeLeft-quantum) name " " (timeLeft-quantum) timeLeft quantum timestamp += quantum timestamp quantum {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			} timestamp += timeLeft timestamp timeLeft System.out.println(name + " " + (timestamp)) System.out.println System.out System System.out name + " " + (timestamp) name + " " + (timestamp) name " " (timestamp) String[] args args public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		LinkedList<String> processes = new LinkedList<>();
		int numProcesses = scanner.nextInt();
		int quantum = scanner.nextInt();
		int timestamp = 0;
		String result = "";
		//get all processes from scanner
		scanner.nextLine();
		for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		}
		scanner.close();
		
		while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		}
	}
} public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		LinkedList<String> processes = new LinkedList<>();
		int numProcesses = scanner.nextInt();
		int quantum = scanner.nextInt();
		int timestamp = 0;
		String result = "";
		//get all processes from scanner
		scanner.nextLine();
		for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		}
		scanner.close();
		
		while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		}
	}
} Main
import java.util.Scanner;
import java.util.LinkedList;

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		LinkedList<String> processes = new LinkedList<>();
		int numProcesses = scanner.nextInt();
		int quantum = scanner.nextInt();
		int timestamp = 0;
		String result = "";
		//get all processes from scanner
		scanner.nextLine();
		for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		}
		scanner.close();
		
		while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		}
	}
}
