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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		Queue<Process> Q = new ArrayDeque<>();

		for (int i=0; i<n; i++) {
			Q.add(new Process(sc.next(), sc.nextInt()));
		}

		int t = 0;
		while (!Q.isEmpty()) {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		}

		sc.close();
	}

	static class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = 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 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		Queue<Process> Q = new ArrayDeque<>();

		for (int i=0; i<n; i++) {
			Q.add(new Process(sc.next(), sc.nextInt()));
		}

		int t = 0;
		while (!Q.isEmpty()) {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		}

		sc.close();
	}

	static class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		Queue<Process> Q = new ArrayDeque<>();

		for (int i=0; i<n; i++) {
			Q.add(new Process(sc.next(), sc.nextInt()));
		}

		int t = 0;
		while (!Q.isEmpty()) {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		}

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		Queue<Process> Q = new ArrayDeque<>();

		for (int i=0; i<n; i++) {
			Q.add(new Process(sc.next(), sc.nextInt()));
		}

		int t = 0;
		while (!Q.isEmpty()) {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		}

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Queue<Process> Q = new ArrayDeque<>(); Q new ArrayDeque<>() for (int i=0; i<n; i++) {
			Q.add(new Process(sc.next(), sc.nextInt()));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			Q.add(new Process(sc.next(), sc.nextInt()));
		} {
			Q.add(new Process(sc.next(), sc.nextInt()));
		} Q.add(new Process(sc.next(), sc.nextInt())) Q.add Q new Process(sc.next(), sc.nextInt()) int t = 0; t 0 while (!Q.isEmpty()) {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		} !Q.isEmpty() Q.isEmpty() Q.isEmpty Q {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		} Process p = Q.poll(); p Q.poll() Q.poll Q if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			} p.time<=q p.time p p.time q {
				t += p.time;
				System.out.println(p.name + " " + t);
			} t += p.time t p.time p p.time System.out.println(p.name + " " + t) System.out.println System.out System System.out p.name + " " + t p.name + " " + t p.name p p.name " " t {
				t += q;
				p.time -= q;
				Q.add(p);
			} t += q t q p.time -= q p.time p p.time q Q.add(p) Q.add Q p sc.close() sc.close sc String[] args args static 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 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		Queue<Process> Q = new ArrayDeque<>();

		for (int i=0; i<n; i++) {
			Q.add(new Process(sc.next(), sc.nextInt()));
		}

		int t = 0;
		while (!Q.isEmpty()) {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		}

		sc.close();
	}

	static class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		Queue<Process> Q = new ArrayDeque<>();

		for (int i=0; i<n; i++) {
			Q.add(new Process(sc.next(), sc.nextInt()));
		}

		int t = 0;
		while (!Q.isEmpty()) {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		}

		sc.close();
	}

	static class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		Queue<Process> Q = new ArrayDeque<>();

		for (int i=0; i<n; i++) {
			Q.add(new Process(sc.next(), sc.nextInt()));
		}

		int t = 0;
		while (!Q.isEmpty()) {
			Process p = Q.poll();
			if (p.time<=q) {
				t += p.time;
				System.out.println(p.name + " " + t);
			} else {
				t += q;
				p.time -= q;
				Q.add(p);
			}
		}

		sc.close();
	}

	static class Process {
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}

}