/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp
 */
import java.util.*;

class Task {
	String name;
	int time;
	int endTime;
	Task(String name, int time) {
		this.name = name;
		this.time = time;
	}
	void setEndTime(int x) {
		this.endTime = x;
	}
}

public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		//Task[] tasks = new Task[n];
		LinkedList<Task> tasks = new LinkedList<Task>();
		for (int i = 0; i < n; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		}

		Task[] result = new Task[n];
		int topOfResult = 0;
		
		int time = 0;
		int idx = 0;
		while (topOfResult < n) {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		}
		
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i].name + " " + result[i].endTime);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}
 import java.util.*; util.* java class Task {
	String name;
	int time;
	int endTime;
	Task(String name, int time) {
		this.name = name;
		this.time = time;
	}
	void setEndTime(int x) {
		this.endTime = x;
	}
} Task String name; name int time; time int endTime; endTime Task(String name, int time) {
		this.name = name;
		this.time = time;
	} Task {
		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 void setEndTime(int x) {
		this.endTime = x;
	} setEndTime {
		this.endTime = x;
	} this.endTime = x this.endTime this this.endTime x int x x public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		//Task[] tasks = new Task[n];
		LinkedList<Task> tasks = new LinkedList<Task>();
		for (int i = 0; i < n; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		}

		Task[] result = new Task[n];
		int topOfResult = 0;
		
		int time = 0;
		int idx = 0;
		while (topOfResult < n) {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		}
		
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i].name + " " + result[i].endTime);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

} Main void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		//Task[] tasks = new Task[n];
		LinkedList<Task> tasks = new LinkedList<Task>();
		for (int i = 0; i < n; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		}

		Task[] result = new Task[n];
		int topOfResult = 0;
		
		int time = 0;
		int idx = 0;
		while (topOfResult < n) {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		}
		
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i].name + " " + result[i].endTime);
		}
	} run {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		//Task[] tasks = new Task[n];
		LinkedList<Task> tasks = new LinkedList<Task>();
		for (int i = 0; i < n; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		}

		Task[] result = new Task[n];
		int topOfResult = 0;
		
		int time = 0;
		int idx = 0;
		while (topOfResult < n) {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		}
		
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i].name + " " + result[i].endTime);
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan LinkedList<Task> tasks = new LinkedList<Task>(); tasks new LinkedList<Task>() for (int i = 0; i < n; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		} {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		} String name = scan.next(); name scan.next() scan.next scan int time = scan.nextInt(); time scan.nextInt() scan.nextInt scan tasks.add(new Task(name, time)) tasks.add tasks new Task(name, time) Task[] result = new Task[n]; result new Task[n] n int topOfResult = 0; topOfResult 0 int time = 0; time 0 int idx = 0; idx 0 while (topOfResult < n) {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		} topOfResult < n topOfResult n {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		} Task task = tasks.pop(); task tasks.pop() tasks.pop tasks if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			} task.time > q task.time task task.time q {
				task.time -= q;
				time += q;
				tasks.add(task);
			} task.time -= q task.time task task.time q time += q time q tasks.add(task) tasks.add tasks task if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			} task.time > 0 task.time task task.time 0 {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			} time += task.time time task.time task task.time task.time = 0 task.time task task.time 0 task.setEndTime(time) task.setEndTime task time result[topOfResult++] = task result[topOfResult++] result topOfResult++ topOfResult task if (++idx >= n) idx = 0; ++idx >= n ++idx idx n idx = 0 idx 0 for (int i = 0; i < result.length; i++) {
			System.out.println(result[i].name + " " + result[i].endTime);
		} int i = 0; int i = 0; i 0 i < result.length i result.length result result.length i++ i++ i {
			System.out.println(result[i].name + " " + result[i].endTime);
		} {
			System.out.println(result[i].name + " " + result[i].endTime);
		} System.out.println(result[i].name + " " + result[i].endTime) System.out.println System.out System System.out result[i].name + " " + result[i].endTime result[i].name + " " + result[i].endTime result[i].name result[i] result i result[i].name " " result[i].endTime result[i] result i result[i].endTime public static void main(String[] args) {
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		//Task[] tasks = new Task[n];
		LinkedList<Task> tasks = new LinkedList<Task>();
		for (int i = 0; i < n; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		}

		Task[] result = new Task[n];
		int topOfResult = 0;
		
		int time = 0;
		int idx = 0;
		while (topOfResult < n) {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		}
		
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i].name + " " + result[i].endTime);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

} public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		//Task[] tasks = new Task[n];
		LinkedList<Task> tasks = new LinkedList<Task>();
		for (int i = 0; i < n; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		}

		Task[] result = new Task[n];
		int topOfResult = 0;
		
		int time = 0;
		int idx = 0;
		while (topOfResult < n) {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		}
		
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i].name + " " + result[i].endTime);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

} Main
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp
 */
import java.util.*;

class Task {
	String name;
	int time;
	int endTime;
	Task(String name, int time) {
		this.name = name;
		this.time = time;
	}
	void setEndTime(int x) {
		this.endTime = x;
	}
}

public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		//Task[] tasks = new Task[n];
		LinkedList<Task> tasks = new LinkedList<Task>();
		for (int i = 0; i < n; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			//tasks[i] = new Task(name, time);
			tasks.add(new Task(name, time));
		}

		Task[] result = new Task[n];
		int topOfResult = 0;
		
		int time = 0;
		int idx = 0;
		while (topOfResult < n) {
			Task task = tasks.pop();
			if (task.time > q) {
				task.time -= q;
				time += q;
				tasks.add(task);
			} else if (task.time > 0) {
				time += task.time;
				task.time = 0;
				task.setEndTime(time);
				result[topOfResult++] = task;
			}
			if (++idx >= n) idx = 0;
		}
		
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i].name + " " + result[i].endTime);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

