import java.util.Scanner;

public class Main {
	static Process[] stack;
	static int firstPointer = 0;
	static int lastPointer;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int processNum = sc.nextInt();
		int quanTime = sc.nextInt();
		stack  = new Process[processNum + 1];
		for(int i = 0; i < processNum; i++) {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		}
		sc.close();
		lastPointer = processNum - 1;
		int time = 0;
		Process[] answerProcesses = new Process[processNum];
		int answerProcessesIndex = 0;
		while(stack[firstPointer] != null) {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		}
		for(Process process: answerProcesses) {
			System.out.println(process.name + " " + process.time);
		}
	}
	public static void enquene(Process process) {
		if(lastPointer == stack.length - 1) {
			lastPointer = 0;
		} else {
			lastPointer++;
		}
		stack[lastPointer] = process;
	}
	public static Process dequene() {
		Process process = stack[firstPointer];
		stack[firstPointer] = null;
		if(firstPointer == stack.length - 1) {
			firstPointer = 0;
		} else {
			firstPointer++;
		}
		return process;
	}
}
class Process {
	String name;
	int time;
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static Process[] stack;
	static int firstPointer = 0;
	static int lastPointer;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int processNum = sc.nextInt();
		int quanTime = sc.nextInt();
		stack  = new Process[processNum + 1];
		for(int i = 0; i < processNum; i++) {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		}
		sc.close();
		lastPointer = processNum - 1;
		int time = 0;
		Process[] answerProcesses = new Process[processNum];
		int answerProcessesIndex = 0;
		while(stack[firstPointer] != null) {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		}
		for(Process process: answerProcesses) {
			System.out.println(process.name + " " + process.time);
		}
	}
	public static void enquene(Process process) {
		if(lastPointer == stack.length - 1) {
			lastPointer = 0;
		} else {
			lastPointer++;
		}
		stack[lastPointer] = process;
	}
	public static Process dequene() {
		Process process = stack[firstPointer];
		stack[firstPointer] = null;
		if(firstPointer == stack.length - 1) {
			firstPointer = 0;
		} else {
			firstPointer++;
		}
		return process;
	}
} Main static Process[] stack; stack static int firstPointer = 0; firstPointer 0 static int lastPointer; lastPointer public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int processNum = sc.nextInt();
		int quanTime = sc.nextInt();
		stack  = new Process[processNum + 1];
		for(int i = 0; i < processNum; i++) {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		}
		sc.close();
		lastPointer = processNum - 1;
		int time = 0;
		Process[] answerProcesses = new Process[processNum];
		int answerProcessesIndex = 0;
		while(stack[firstPointer] != null) {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		}
		for(Process process: answerProcesses) {
			System.out.println(process.name + " " + process.time);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int processNum = sc.nextInt();
		int quanTime = sc.nextInt();
		stack  = new Process[processNum + 1];
		for(int i = 0; i < processNum; i++) {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		}
		sc.close();
		lastPointer = processNum - 1;
		int time = 0;
		Process[] answerProcesses = new Process[processNum];
		int answerProcessesIndex = 0;
		while(stack[firstPointer] != null) {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		}
		for(Process process: answerProcesses) {
			System.out.println(process.name + " " + process.time);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int processNum = sc.nextInt(); processNum sc.nextInt() sc.nextInt sc int quanTime = sc.nextInt(); quanTime sc.nextInt() sc.nextInt sc stack  = new Process[processNum + 1] stack new Process[processNum + 1] processNum + 1 processNum 1 for(int i = 0; i < processNum; i++) {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		} int i = 0; int i = 0; i 0 i < processNum i processNum i++ i++ i {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		} {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		} Process process = new Process(sc.next(), sc.nextInt()); process new Process(sc.next(), sc.nextInt()) stack[i] = process stack[i] stack i process sc.close() sc.close sc lastPointer = processNum - 1 lastPointer processNum - 1 processNum 1 int time = 0; time 0 Process[] answerProcesses = new Process[processNum]; answerProcesses new Process[processNum] processNum int answerProcessesIndex = 0; answerProcessesIndex 0 while(stack[firstPointer] != null) {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		} stack[firstPointer] != null stack[firstPointer] stack firstPointer null {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		} Process process = dequene(); process dequene() dequene int processTime = process.time; processTime process.time process process.time if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			} processTime <= quanTime processTime quanTime {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} time += processTime time processTime process.time = time process.time process process.time time answerProcesses[answerProcessesIndex] = process answerProcesses[answerProcessesIndex] answerProcesses answerProcessesIndex process answerProcessesIndex++ answerProcessesIndex {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			} time += quanTime time quanTime process.time -= quanTime process.time process process.time quanTime enquene(process) enquene process for(Process process: answerProcesses) {
			System.out.println(process.name + " " + process.time);
		} Process process answerProcesses {
			System.out.println(process.name + " " + process.time);
		} {
			System.out.println(process.name + " " + process.time);
		} System.out.println(process.name + " " + process.time) System.out.println System.out System System.out process.name + " " + process.time process.name + " " + process.time process.name process process.name " " process.time process process.time String[] args args public static void enquene(Process process) {
		if(lastPointer == stack.length - 1) {
			lastPointer = 0;
		} else {
			lastPointer++;
		}
		stack[lastPointer] = process;
	} enquene {
		if(lastPointer == stack.length - 1) {
			lastPointer = 0;
		} else {
			lastPointer++;
		}
		stack[lastPointer] = process;
	} if(lastPointer == stack.length - 1) {
			lastPointer = 0;
		} else {
			lastPointer++;
		} lastPointer == stack.length - 1 lastPointer stack.length - 1 stack.length stack stack.length 1 {
			lastPointer = 0;
		} lastPointer = 0 lastPointer 0 {
			lastPointer++;
		} lastPointer++ lastPointer stack[lastPointer] = process stack[lastPointer] stack lastPointer process Process process process public static Process dequene() {
		Process process = stack[firstPointer];
		stack[firstPointer] = null;
		if(firstPointer == stack.length - 1) {
			firstPointer = 0;
		} else {
			firstPointer++;
		}
		return process;
	} dequene {
		Process process = stack[firstPointer];
		stack[firstPointer] = null;
		if(firstPointer == stack.length - 1) {
			firstPointer = 0;
		} else {
			firstPointer++;
		}
		return process;
	} Process process = stack[firstPointer]; process stack[firstPointer] stack firstPointer stack[firstPointer] = null stack[firstPointer] stack firstPointer null if(firstPointer == stack.length - 1) {
			firstPointer = 0;
		} else {
			firstPointer++;
		} firstPointer == stack.length - 1 firstPointer stack.length - 1 stack.length stack stack.length 1 {
			firstPointer = 0;
		} firstPointer = 0 firstPointer 0 {
			firstPointer++;
		} firstPointer++ firstPointer return process; process class Process {
	String name;
	int time;
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} Process String name; name int time; time public Process(String name, int time) {
		this.name = name;
		this.time = time;
	} Process {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public class Main {
	static Process[] stack;
	static int firstPointer = 0;
	static int lastPointer;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int processNum = sc.nextInt();
		int quanTime = sc.nextInt();
		stack  = new Process[processNum + 1];
		for(int i = 0; i < processNum; i++) {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		}
		sc.close();
		lastPointer = processNum - 1;
		int time = 0;
		Process[] answerProcesses = new Process[processNum];
		int answerProcessesIndex = 0;
		while(stack[firstPointer] != null) {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		}
		for(Process process: answerProcesses) {
			System.out.println(process.name + " " + process.time);
		}
	}
	public static void enquene(Process process) {
		if(lastPointer == stack.length - 1) {
			lastPointer = 0;
		} else {
			lastPointer++;
		}
		stack[lastPointer] = process;
	}
	public static Process dequene() {
		Process process = stack[firstPointer];
		stack[firstPointer] = null;
		if(firstPointer == stack.length - 1) {
			firstPointer = 0;
		} else {
			firstPointer++;
		}
		return process;
	}
} public class Main {
	static Process[] stack;
	static int firstPointer = 0;
	static int lastPointer;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int processNum = sc.nextInt();
		int quanTime = sc.nextInt();
		stack  = new Process[processNum + 1];
		for(int i = 0; i < processNum; i++) {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		}
		sc.close();
		lastPointer = processNum - 1;
		int time = 0;
		Process[] answerProcesses = new Process[processNum];
		int answerProcessesIndex = 0;
		while(stack[firstPointer] != null) {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		}
		for(Process process: answerProcesses) {
			System.out.println(process.name + " " + process.time);
		}
	}
	public static void enquene(Process process) {
		if(lastPointer == stack.length - 1) {
			lastPointer = 0;
		} else {
			lastPointer++;
		}
		stack[lastPointer] = process;
	}
	public static Process dequene() {
		Process process = stack[firstPointer];
		stack[firstPointer] = null;
		if(firstPointer == stack.length - 1) {
			firstPointer = 0;
		} else {
			firstPointer++;
		}
		return process;
	}
} Main
import java.util.Scanner;

public class Main {
	static Process[] stack;
	static int firstPointer = 0;
	static int lastPointer;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int processNum = sc.nextInt();
		int quanTime = sc.nextInt();
		stack  = new Process[processNum + 1];
		for(int i = 0; i < processNum; i++) {
			Process process = new Process(sc.next(), sc.nextInt());
			stack[i] = process;
		}
		sc.close();
		lastPointer = processNum - 1;
		int time = 0;
		Process[] answerProcesses = new Process[processNum];
		int answerProcessesIndex = 0;
		while(stack[firstPointer] != null) {
			Process process = dequene();
			int processTime = process.time;
			if(processTime <= quanTime) {
				time += processTime;
				process.time = time;
				answerProcesses[answerProcessesIndex] = process;
				answerProcessesIndex++;
			} else {
				time += quanTime;
				process.time -= quanTime;
				enquene(process);
			}
		}
		for(Process process: answerProcesses) {
			System.out.println(process.name + " " + process.time);
		}
	}
	public static void enquene(Process process) {
		if(lastPointer == stack.length - 1) {
			lastPointer = 0;
		} else {
			lastPointer++;
		}
		stack[lastPointer] = process;
	}
	public static Process dequene() {
		Process process = stack[firstPointer];
		stack[firstPointer] = null;
		if(firstPointer == stack.length - 1) {
			firstPointer = 0;
		} else {
			firstPointer++;
		}
		return process;
	}
}
class Process {
	String name;
	int time;
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
}