import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	public static void runSchedule(Queue<String[]> tasks, int quantum) {
		int totalTime = 0;
		
		while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		}
		
		
	}
	

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int nTasks = scan.nextInt();
		int quantum = scan.nextInt();
		scan.nextLine();
		
		Queue<String[]> tasks = new ArrayDeque<>();
		
		for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		}
		scan.close();
		
		runSchedule(tasks, quantum);
	}

}
 import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
	
	public static void runSchedule(Queue<String[]> tasks, int quantum) {
		int totalTime = 0;
		
		while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		}
		
		
	}
	

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int nTasks = scan.nextInt();
		int quantum = scan.nextInt();
		scan.nextLine();
		
		Queue<String[]> tasks = new ArrayDeque<>();
		
		for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		}
		scan.close();
		
		runSchedule(tasks, quantum);
	}

} Main public static void runSchedule(Queue<String[]> tasks, int quantum) {
		int totalTime = 0;
		
		while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		}
		
		
	} runSchedule {
		int totalTime = 0;
		
		while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		}
		
		
	} int totalTime = 0; totalTime 0 while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		} !tasks.isEmpty() tasks.isEmpty() tasks.isEmpty tasks {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		} String[] elem = tasks.poll(); elem tasks.poll() tasks.poll tasks int reqTime = Integer.valueOf(elem[1]); reqTime Integer.valueOf(elem[1]) Integer.valueOf Integer elem[1] elem 1 int timeElapsed = quantum - reqTime; timeElapsed quantum - reqTime quantum reqTime if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			} timeElapsed >= 0 timeElapsed 0 {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} totalTime += reqTime totalTime reqTime System.out.println(elem[0] + " " + totalTime) System.out.println System.out System System.out elem[0] + " " + totalTime elem[0] + " " + totalTime elem[0] elem 0 " " totalTime {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			} totalTime += quantum totalTime quantum elem[1] = String.valueOf(timeElapsed * -1) elem[1] elem 1 String.valueOf(timeElapsed * -1) String.valueOf String timeElapsed * -1 timeElapsed -1 1 tasks.add(elem) tasks.add tasks elem Queue<String[]> tasks tasks int quantum quantum public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int nTasks = scan.nextInt();
		int quantum = scan.nextInt();
		scan.nextLine();
		
		Queue<String[]> tasks = new ArrayDeque<>();
		
		for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		}
		scan.close();
		
		runSchedule(tasks, quantum);
	} main {
		Scanner scan = new Scanner(System.in);
		int nTasks = scan.nextInt();
		int quantum = scan.nextInt();
		scan.nextLine();
		
		Queue<String[]> tasks = new ArrayDeque<>();
		
		for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		}
		scan.close();
		
		runSchedule(tasks, quantum);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int nTasks = scan.nextInt(); nTasks scan.nextInt() scan.nextInt scan int quantum = scan.nextInt(); quantum scan.nextInt() scan.nextInt scan scan.nextLine() scan.nextLine scan Queue<String[]> tasks = new ArrayDeque<>(); tasks new ArrayDeque<>() for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		} int i = 0; int i = 0; i 0 i < nTasks i nTasks i++ i++ i {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		} {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		} String[] str = scan.nextLine().split(" "); str scan.nextLine().split(" ") scan.nextLine().split scan.nextLine() scan.nextLine scan " " tasks.add(str) tasks.add tasks str scan.close() scan.close scan runSchedule(tasks, quantum) runSchedule tasks quantum String[] args args public class Main {
	
	public static void runSchedule(Queue<String[]> tasks, int quantum) {
		int totalTime = 0;
		
		while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		}
		
		
	}
	

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int nTasks = scan.nextInt();
		int quantum = scan.nextInt();
		scan.nextLine();
		
		Queue<String[]> tasks = new ArrayDeque<>();
		
		for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		}
		scan.close();
		
		runSchedule(tasks, quantum);
	}

} public class Main {
	
	public static void runSchedule(Queue<String[]> tasks, int quantum) {
		int totalTime = 0;
		
		while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		}
		
		
	}
	

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int nTasks = scan.nextInt();
		int quantum = scan.nextInt();
		scan.nextLine();
		
		Queue<String[]> tasks = new ArrayDeque<>();
		
		for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		}
		scan.close();
		
		runSchedule(tasks, quantum);
	}

} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	public static void runSchedule(Queue<String[]> tasks, int quantum) {
		int totalTime = 0;
		
		while (!tasks.isEmpty()) {
			String[] elem = tasks.poll();
			int reqTime = Integer.valueOf(elem[1]);
			int timeElapsed = quantum - reqTime;
			
			if (timeElapsed >= 0) {
				totalTime += reqTime;
				System.out.println(elem[0] + " " + totalTime);
			} else {
				totalTime += quantum;
				elem[1] = String.valueOf(timeElapsed * -1);
				tasks.add(elem);
			}
		}
		
		
	}
	

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int nTasks = scan.nextInt();
		int quantum = scan.nextInt();
		scan.nextLine();
		
		Queue<String[]> tasks = new ArrayDeque<>();
		
		for (int i = 0; i < nTasks; i++) {
			String[] str = scan.nextLine().split(" ");
			tasks.add(str);
		}
		scan.close();
		
		runSchedule(tasks, quantum);
	}

}

