import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) throws IOException {
		final LinkedList<Process> processes = getProcesses();
		final String result = runProcessing(processes);
		
		System.out.print(result);
	}
	
	private static int quantum;
	public static String runProcessing(final LinkedList<Process> processes) {
		final StringBuilder result = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		
		Process process;
		int elapsed = 0;
		while ((process = processes.poll()) != null) {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		}
		
		return result.toString();
	}
	
	public static LinkedList<Process> getProcesses() throws IOException {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final String[] requirement = reader.readLine().split(" ");

		final int numberOfPprocess = Integer.parseInt(requirement[0]);
		quantum = Integer.parseInt(requirement[1]);
		
		final LinkedList<Process> processes = new LinkedList<Process>();
		for (int i = 0; i < numberOfPprocess; i++) {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		}

		return processes;
	}
}

class Process {
	String name;
	int processingTime;

	public Process(String name, int processingTime) {
		this.name = name;
		this.processingTime = processingTime;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.LinkedList; LinkedList java.util public class Main {
	public static void main(String[] args) throws IOException {
		final LinkedList<Process> processes = getProcesses();
		final String result = runProcessing(processes);
		
		System.out.print(result);
	}
	
	private static int quantum;
	public static String runProcessing(final LinkedList<Process> processes) {
		final StringBuilder result = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		
		Process process;
		int elapsed = 0;
		while ((process = processes.poll()) != null) {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		}
		
		return result.toString();
	}
	
	public static LinkedList<Process> getProcesses() throws IOException {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final String[] requirement = reader.readLine().split(" ");

		final int numberOfPprocess = Integer.parseInt(requirement[0]);
		quantum = Integer.parseInt(requirement[1]);
		
		final LinkedList<Process> processes = new LinkedList<Process>();
		for (int i = 0; i < numberOfPprocess; i++) {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		}

		return processes;
	}
} Main private static int quantum; quantum public static void main(String[] args) throws IOException {
		final LinkedList<Process> processes = getProcesses();
		final String result = runProcessing(processes);
		
		System.out.print(result);
	} main {
		final LinkedList<Process> processes = getProcesses();
		final String result = runProcessing(processes);
		
		System.out.print(result);
	} final LinkedList<Process> processes = getProcesses(); processes getProcesses() getProcesses final String result = runProcessing(processes); result runProcessing(processes) runProcessing processes System.out.print(result) System.out.print System.out System System.out result String[] args args public static String runProcessing(final LinkedList<Process> processes) {
		final StringBuilder result = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		
		Process process;
		int elapsed = 0;
		while ((process = processes.poll()) != null) {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		}
		
		return result.toString();
	} runProcessing {
		final StringBuilder result = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		
		Process process;
		int elapsed = 0;
		while ((process = processes.poll()) != null) {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		}
		
		return result.toString();
	} final StringBuilder result = new StringBuilder(); result new StringBuilder() final String lb = System.getProperty("line.separator"); lb System.getProperty("line.separator") System.getProperty System "line.separator" Process process; process int elapsed = 0; elapsed 0 while ((process = processes.poll()) != null) {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		} (process = processes.poll()) != null (process = processes.poll()) process processes.poll() processes.poll processes null {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		} if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			} quantum < process.processingTime quantum process.processingTime process process.processingTime {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} elapsed += quantum elapsed quantum process.processingTime -= quantum process.processingTime process process.processingTime quantum processes.add(process) processes.add processes process {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			} elapsed += process.processingTime elapsed process.processingTime process process.processingTime result.append(process.name).append(" ").append(elapsed).append(lb) result.append(process.name).append(" ").append(elapsed).append result.append(process.name).append(" ").append(elapsed) result.append(process.name).append(" ").append result.append(process.name).append(" ") result.append(process.name).append result.append(process.name) result.append result process.name process process.name " " elapsed lb return result.toString(); result.toString() result.toString result final LinkedList<Process> processes processes public static LinkedList<Process> getProcesses() throws IOException {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final String[] requirement = reader.readLine().split(" ");

		final int numberOfPprocess = Integer.parseInt(requirement[0]);
		quantum = Integer.parseInt(requirement[1]);
		
		final LinkedList<Process> processes = new LinkedList<Process>();
		for (int i = 0; i < numberOfPprocess; i++) {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		}

		return processes;
	} getProcesses {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final String[] requirement = reader.readLine().split(" ");

		final int numberOfPprocess = Integer.parseInt(requirement[0]);
		quantum = Integer.parseInt(requirement[1]);
		
		final LinkedList<Process> processes = new LinkedList<Process>();
		for (int i = 0; i < numberOfPprocess; i++) {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		}

		return processes;
	} final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) final String[] requirement = reader.readLine().split(" "); requirement reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " final int numberOfPprocess = Integer.parseInt(requirement[0]); numberOfPprocess Integer.parseInt(requirement[0]) Integer.parseInt Integer requirement[0] requirement 0 quantum = Integer.parseInt(requirement[1]) quantum Integer.parseInt(requirement[1]) Integer.parseInt Integer requirement[1] requirement 1 final LinkedList<Process> processes = new LinkedList<Process>(); processes new LinkedList<Process>() for (int i = 0; i < numberOfPprocess; i++) {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		} int i = 0; int i = 0; i 0 i < numberOfPprocess i numberOfPprocess i++ i++ i {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		} {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		} final String[] line = reader.readLine().split(" "); line reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " processes.add(new Process(line[0], Integer.parseInt(line[1]))) processes.add processes new Process(line[0], Integer.parseInt(line[1])) return processes; processes class Process {
	String name;
	int processingTime;

	public Process(String name, int processingTime) {
		this.name = name;
		this.processingTime = processingTime;
	}
} Process String name; name int processingTime; processingTime public Process(String name, int processingTime) {
		this.name = name;
		this.processingTime = processingTime;
	} Process {
		this.name = name;
		this.processingTime = processingTime;
	} this.name = name this.name this this.name name this.processingTime = processingTime this.processingTime this this.processingTime processingTime String name name int processingTime processingTime public class Main {
	public static void main(String[] args) throws IOException {
		final LinkedList<Process> processes = getProcesses();
		final String result = runProcessing(processes);
		
		System.out.print(result);
	}
	
	private static int quantum;
	public static String runProcessing(final LinkedList<Process> processes) {
		final StringBuilder result = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		
		Process process;
		int elapsed = 0;
		while ((process = processes.poll()) != null) {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		}
		
		return result.toString();
	}
	
	public static LinkedList<Process> getProcesses() throws IOException {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final String[] requirement = reader.readLine().split(" ");

		final int numberOfPprocess = Integer.parseInt(requirement[0]);
		quantum = Integer.parseInt(requirement[1]);
		
		final LinkedList<Process> processes = new LinkedList<Process>();
		for (int i = 0; i < numberOfPprocess; i++) {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		}

		return processes;
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		final LinkedList<Process> processes = getProcesses();
		final String result = runProcessing(processes);
		
		System.out.print(result);
	}
	
	private static int quantum;
	public static String runProcessing(final LinkedList<Process> processes) {
		final StringBuilder result = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		
		Process process;
		int elapsed = 0;
		while ((process = processes.poll()) != null) {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		}
		
		return result.toString();
	}
	
	public static LinkedList<Process> getProcesses() throws IOException {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final String[] requirement = reader.readLine().split(" ");

		final int numberOfPprocess = Integer.parseInt(requirement[0]);
		quantum = Integer.parseInt(requirement[1]);
		
		final LinkedList<Process> processes = new LinkedList<Process>();
		for (int i = 0; i < numberOfPprocess; i++) {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		}

		return processes;
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) throws IOException {
		final LinkedList<Process> processes = getProcesses();
		final String result = runProcessing(processes);
		
		System.out.print(result);
	}
	
	private static int quantum;
	public static String runProcessing(final LinkedList<Process> processes) {
		final StringBuilder result = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		
		Process process;
		int elapsed = 0;
		while ((process = processes.poll()) != null) {
			if (quantum < process.processingTime) {
				elapsed += quantum;
				process.processingTime -= quantum;
				processes.add(process);
				
			} else {
				elapsed += process.processingTime;
				result.append(process.name).append(" ").append(elapsed).append(lb);
			}
		}
		
		return result.toString();
	}
	
	public static LinkedList<Process> getProcesses() throws IOException {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final String[] requirement = reader.readLine().split(" ");

		final int numberOfPprocess = Integer.parseInt(requirement[0]);
		quantum = Integer.parseInt(requirement[1]);
		
		final LinkedList<Process> processes = new LinkedList<Process>();
		for (int i = 0; i < numberOfPprocess; i++) {
			final String[] line = reader.readLine().split(" ");
			processes.add(new Process(line[0], Integer.parseInt(line[1])));
		}

		return processes;
	}
}

class Process {
	String name;
	int processingTime;

	public Process(String name, int processingTime) {
		this.name = name;
		this.processingTime = processingTime;
	}
}