import java.util.*;

public class Main {
	class Process {
		String name;
		int time;
		Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
	void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		}
		for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}
 import java.util.*; util.* java public class Main {
	class Process {
		String name;
		int time;
		Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
	void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		}
		for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} Main void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		}
		for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		}
	} run {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		}
		for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int q = scanner.nextInt(); q scanner.nextInt() scanner.nextInt scanner Queue<Process> que = new LinkedList<Process>(); que new LinkedList<Process>() for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		} {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		} String name = scanner.next(); name scanner.next() scanner.next scanner int time = scanner.nextInt(); time scanner.nextInt() scanner.nextInt scanner que.add(new Process(name, time)) que.add que new Process(name, time) for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		} int time = 0; int time = 0; time 0 !que.isEmpty() que.isEmpty() que.isEmpty que {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		} {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		} Process p = que.poll(); p que.poll() que.poll que if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			} p.time - q <= 0 p.time - q p.time p p.time q 0 {
				time += p.time;
				System.out.println(p.name + " " + time);
			} time += p.time time p.time p p.time System.out.println(p.name + " " + time) System.out.println System.out System System.out p.name + " " + time p.name + " " + time p.name p p.name " " time {
				p.time -= q;
				que.add(p);
				time += q;
			} p.time -= q p.time p p.time q que.add(p) que.add que p time += q time q public static void main(String[] args) {
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args class Process {
		String name;
		int time;
		Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	} Process String name; name int time; time 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 {
	class Process {
		String name;
		int time;
		Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
	void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		}
		for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} public class Main {
	class Process {
		String name;
		int time;
		Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
	void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		}
		for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} Main
import java.util.*;

public class Main {
	class Process {
		String name;
		int time;
		Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
	void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		}
		for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

