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

public class Main {
	int n,q;
	Queue<Process> process;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		q = scan.nextInt();
		process = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		}
	}
	void run() {
		int sumTime = 0;
		while (true) {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		}
	}
}
class Process {
	String name;
	int time;
	Process(String txt, int num) {
		name = txt;
		time = num;
	}
	public String toString() {
		return name + " : " + time;
	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
	int n,q;
	Queue<Process> process;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		q = scan.nextInt();
		process = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		}
	}
	void run() {
		int sumTime = 0;
		while (true) {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		}
	}
} Main int n n q; q Queue<Process> process; process public static void main(String args[]) {
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String args[] args Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		q = scan.nextInt();
		process = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		}
	} Main {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		q = scan.nextInt();
		process = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) n = scan.nextInt() n scan.nextInt() scan.nextInt scan q = scan.nextInt() q scan.nextInt() scan.nextInt scan process = new ArrayDeque<Process>() process new ArrayDeque<Process>() for (int i = 0; i < n; i++) {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		} {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		} Process p = new Process(scan.next(),scan.nextInt()); p new Process(scan.next(),scan.nextInt()) process.add(p) process.add process p void run() {
		int sumTime = 0;
		while (true) {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		}
	} run {
		int sumTime = 0;
		while (true) {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		}
	} int sumTime = 0; sumTime 0 while (true) {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		} true {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		} Process p = process.poll(); p process.poll() process.poll process if (p == null) break; p == null p null break; if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			} p.time > q p.time p p.time q {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} p.time -= q p.time p p.time q process.add(p) process.add process p sumTime += q sumTime q if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			} p.time <= q p.time p p.time q {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			} sumTime += p.time sumTime p.time p p.time System.out.println(p.name + " " + sumTime) System.out.println System.out System System.out p.name + " " + sumTime p.name + " " + sumTime p.name p p.name " " sumTime class Process {
	String name;
	int time;
	Process(String txt, int num) {
		name = txt;
		time = num;
	}
	public String toString() {
		return name + " : " + time;
	}
} Process String name; name int time; time Process(String txt, int num) {
		name = txt;
		time = num;
	} Process {
		name = txt;
		time = num;
	} name = txt name txt time = num time num String txt txt int num num public String toString() {
		return name + " : " + time;
	} toString {
		return name + " : " + time;
	} return name + " : " + time; name + " : " + time name + " : " + time name " : " time public class Main {
	int n,q;
	Queue<Process> process;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		q = scan.nextInt();
		process = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		}
	}
	void run() {
		int sumTime = 0;
		while (true) {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		}
	}
} public class Main {
	int n,q;
	Queue<Process> process;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		q = scan.nextInt();
		process = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		}
	}
	void run() {
		int sumTime = 0;
		while (true) {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		}
	}
} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	int n,q;
	Queue<Process> process;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		q = scan.nextInt();
		process = new ArrayDeque<Process>();
		for (int i = 0; i < n; i++) {
			Process p = new Process(scan.next(),scan.nextInt());
			process.add(p);
		}
	}
	void run() {
		int sumTime = 0;
		while (true) {
			Process p = process.poll();
			if (p == null) break;
			if (p.time > q) {
				p.time -= q;
				process.add(p);
				sumTime += q;
			} else if (p.time <= q) {
				sumTime += p.time;
				System.out.println(p.name + " " + sumTime);
			}
		}
	}
}
class Process {
	String name;
	int time;
	Process(String txt, int num) {
		name = txt;
		time = num;
	}
	public String toString() {
		return name + " : " + time;
	}
}
