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

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	}	
}
 import java.util.Scanner; Scanner java.util import java.util.LinkedList; LinkedList java.util public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	}	
} Main public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	} main {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	} Scanner input = new Scanner(System.in); input new Scanner(System.in) int nProcesses = input.nextInt(); nProcesses input.nextInt() input.nextInt input int quantum = input.nextInt(); quantum input.nextInt() input.nextInt input input.nextLine() input.nextLine input LinkedList<Integer> queue = new LinkedList<>(); queue new LinkedList<>() String[] processes = new String[nProcesses]; processes new String[nProcesses] nProcesses int[] times = new int[nProcesses]; times new int[nProcesses] nProcesses for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		} int i = 0; int i = 0; i 0 i < nProcesses i nProcesses i++ i++ i {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		} {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		} processes[i] = input.next() processes[i] processes i input.next() input.next input times[i] = input.nextInt() times[i] times i input.nextInt() input.nextInt input queue.add(i) queue.add queue i input.nextLine() input.nextLine input int elapsedTime = 0; elapsedTime 0 while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		} int processID = queue.removeFirst(); processID queue.removeFirst() queue.removeFirst queue int timeSpent = Math.min(times[processID], quantum); timeSpent Math.min(times[processID], quantum) Math.min Math times[processID] times processID quantum times[processID] -= timeSpent times[processID] times processID timeSpent elapsedTime += timeSpent elapsedTime timeSpent if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			} times[processID] == 0 times[processID] times processID 0 {
				System.out.println(processes[processID] + " " + elapsedTime);
			} System.out.println(processes[processID] + " " + elapsedTime) System.out.println System.out System System.out processes[processID] + " " + elapsedTime processes[processID] + " " + elapsedTime processes[processID] processes processID " " elapsedTime {
				queue.addLast(processID);
			} queue.addLast(processID) queue.addLast queue processID String[] args args public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	}	
} public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	}	
} Main
import java.util.Scanner;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int nProcesses = input.nextInt();
		int quantum = input.nextInt();
		input.nextLine(); // Clear \n.
		
		LinkedList<Integer> queue = new LinkedList<>();
		
		String[] processes = new String[nProcesses];
		int[] times = new int[nProcesses];
		
		for (int i = 0; i < nProcesses; i++) {
			processes[i] = input.next();
			times[i] = input.nextInt();
			queue.add(i); // Add process to queue.
			input.nextLine(); // Clear \n.
		}

		int elapsedTime = 0;
		while (!queue.isEmpty()) {
			int processID = queue.removeFirst();
			int timeSpent = Math.min(times[processID], quantum);
			times[processID] -= timeSpent;
			elapsedTime += timeSpent;
			
			if (times[processID] == 0) {
				System.out.println(processes[processID] + " " + elapsedTime);
			} else {
				queue.addLast(processID);
			}
		}
		
	}	
}

