import java.util.*;

public class Main {
	public static void main(String[] args) {
		class Process {
			private String name;
			private long time;
		}
		Queue<Process> queue = new LinkedList<Process>();		
		Scanner scanner = new Scanner(System.in);
		
		long n = scanner.nextLong();
		long q = scanner.nextLong();
				
		for (int i = 0; i < n; i ++) {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		}
		scanner.close();

		long currentTime = 0;
		
		while (queue.size() > 0) {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		}
	}
} 
 import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		class Process {
			private String name;
			private long time;
		}
		Queue<Process> queue = new LinkedList<Process>();		
		Scanner scanner = new Scanner(System.in);
		
		long n = scanner.nextLong();
		long q = scanner.nextLong();
				
		for (int i = 0; i < n; i ++) {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		}
		scanner.close();

		long currentTime = 0;
		
		while (queue.size() > 0) {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		}
	}
} Main public static void main(String[] args) {
		class Process {
			private String name;
			private long time;
		}
		Queue<Process> queue = new LinkedList<Process>();		
		Scanner scanner = new Scanner(System.in);
		
		long n = scanner.nextLong();
		long q = scanner.nextLong();
				
		for (int i = 0; i < n; i ++) {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		}
		scanner.close();

		long currentTime = 0;
		
		while (queue.size() > 0) {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		}
	} main {
		class Process {
			private String name;
			private long time;
		}
		Queue<Process> queue = new LinkedList<Process>();		
		Scanner scanner = new Scanner(System.in);
		
		long n = scanner.nextLong();
		long q = scanner.nextLong();
				
		for (int i = 0; i < n; i ++) {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		}
		scanner.close();

		long currentTime = 0;
		
		while (queue.size() > 0) {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		}
	} Queue<Process> queue = new LinkedList<Process>(); queue new LinkedList<Process>() Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long n = scanner.nextLong(); n scanner.nextLong() scanner.nextLong scanner long q = scanner.nextLong(); q scanner.nextLong() scanner.nextLong scanner for (int i = 0; i < n; i ++) {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		} int i = 0; int i = 0; i 0 i < n i n i ++ i ++ i {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		} {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		} Process process = new Process(); process new Process() process.name = scanner.next() process.name process process.name scanner.next() scanner.next scanner process.time = scanner.nextLong() process.time process process.time scanner.nextLong() scanner.nextLong scanner queue.add(process) queue.add queue process scanner.close() scanner.close scanner long currentTime = 0; currentTime 0 while (queue.size() > 0) {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		} queue.size() > 0 queue.size() queue.size queue 0 {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		} Process currentProcess = queue.remove(); currentProcess queue.remove() queue.remove queue if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			} currentProcess.time <= q currentProcess.time currentProcess currentProcess.time q {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} currentTime += currentProcess.time currentTime currentProcess.time currentProcess currentProcess.time System.out.println(currentProcess.name + " " + currentTime) System.out.println System.out System System.out currentProcess.name + " " + currentTime currentProcess.name + " " + currentTime currentProcess.name currentProcess currentProcess.name " " currentTime {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			} currentProcess.time -= q currentProcess.time currentProcess currentProcess.time q currentTime += q currentTime q queue.add(currentProcess) queue.add queue currentProcess String[] args args public class Main {
	public static void main(String[] args) {
		class Process {
			private String name;
			private long time;
		}
		Queue<Process> queue = new LinkedList<Process>();		
		Scanner scanner = new Scanner(System.in);
		
		long n = scanner.nextLong();
		long q = scanner.nextLong();
				
		for (int i = 0; i < n; i ++) {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		}
		scanner.close();

		long currentTime = 0;
		
		while (queue.size() > 0) {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		}
	}
} public class Main {
	public static void main(String[] args) {
		class Process {
			private String name;
			private long time;
		}
		Queue<Process> queue = new LinkedList<Process>();		
		Scanner scanner = new Scanner(System.in);
		
		long n = scanner.nextLong();
		long q = scanner.nextLong();
				
		for (int i = 0; i < n; i ++) {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		}
		scanner.close();

		long currentTime = 0;
		
		while (queue.size() > 0) {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		}
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		class Process {
			private String name;
			private long time;
		}
		Queue<Process> queue = new LinkedList<Process>();		
		Scanner scanner = new Scanner(System.in);
		
		long n = scanner.nextLong();
		long q = scanner.nextLong();
				
		for (int i = 0; i < n; i ++) {
			Process process = new Process();
			process.name = scanner.next();
			process.time = scanner.nextLong();
			queue.add(process);
		}
		scanner.close();

		long currentTime = 0;
		
		while (queue.size() > 0) {
			Process currentProcess = queue.remove();
			
			if (currentProcess.time <= q) {
				currentTime += currentProcess.time;
				System.out.println(currentProcess.name + " " + currentTime);
			} else {
				currentProcess.time -= q;
				currentTime += q;
				queue.add(currentProcess);
			}
		}
	}
} 

