
import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int numProcesses = in.nextInt();
		int quantum = in.nextInt();
		Main r = new Main();
		Queue<Process> q = new LinkedList<Process>();

		for (int i = 1; i <= numProcesses; i++) {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		}

		performQOps(q, quantum);
	}

	public static void performQOps(Queue<Process> q, int quantum) {
		int totalTime = 0;

		while (q.size() != 0) {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		}
	}

	private class Process {

		String name;
		int timeRemaining;

		public Process(String name, int timeRemaining) {
			this.name = name;
			this.timeRemaining = timeRemaining;
		}

		public String getName() {
			return name;
		}

		public int getTimeRemaining() {
			return timeRemaining;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setTimeRemaining(int timeRemaining) {
			this.timeRemaining = timeRemaining;
		}

		public String toString() {
			return name;
		}
	}
}
 import java.util.Scanner; Scanner java.util import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int numProcesses = in.nextInt();
		int quantum = in.nextInt();
		Main r = new Main();
		Queue<Process> q = new LinkedList<Process>();

		for (int i = 1; i <= numProcesses; i++) {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		}

		performQOps(q, quantum);
	}

	public static void performQOps(Queue<Process> q, int quantum) {
		int totalTime = 0;

		while (q.size() != 0) {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		}
	}

	private class Process {

		String name;
		int timeRemaining;

		public Process(String name, int timeRemaining) {
			this.name = name;
			this.timeRemaining = timeRemaining;
		}

		public String getName() {
			return name;
		}

		public int getTimeRemaining() {
			return timeRemaining;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setTimeRemaining(int timeRemaining) {
			this.timeRemaining = timeRemaining;
		}

		public String toString() {
			return name;
		}
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int numProcesses = in.nextInt();
		int quantum = in.nextInt();
		Main r = new Main();
		Queue<Process> q = new LinkedList<Process>();

		for (int i = 1; i <= numProcesses; i++) {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		}

		performQOps(q, quantum);
	} main {
		Scanner in = new Scanner(System.in);
		int numProcesses = in.nextInt();
		int quantum = in.nextInt();
		Main r = new Main();
		Queue<Process> q = new LinkedList<Process>();

		for (int i = 1; i <= numProcesses; i++) {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		}

		performQOps(q, quantum);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int numProcesses = in.nextInt(); numProcesses in.nextInt() in.nextInt in int quantum = in.nextInt(); quantum in.nextInt() in.nextInt in Main r = new Main(); r new Main() Queue<Process> q = new LinkedList<Process>(); q new LinkedList<Process>() for (int i = 1; i <= numProcesses; i++) {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		} int i = 1; int i = 1; i 1 i <= numProcesses i numProcesses i++ i++ i {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		} {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		} Process p = r.new Process(in.next(), in.nextInt()); p r.new Process(in.next(), in.nextInt()) r r q.add(p) q.add q p performQOps(q, quantum) performQOps q quantum String[] args args public static void performQOps(Queue<Process> q, int quantum) {
		int totalTime = 0;

		while (q.size() != 0) {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		}
	} performQOps {
		int totalTime = 0;

		while (q.size() != 0) {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		}
	} int totalTime = 0; totalTime 0 while (q.size() != 0) {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		} q.size() != 0 q.size() q.size q 0 {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		} Process cur = q.poll(); cur q.poll() q.poll q if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			} cur.getTimeRemaining() <= quantum cur.getTimeRemaining() cur.getTimeRemaining cur quantum {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} totalTime += cur.getTimeRemaining() totalTime cur.getTimeRemaining() cur.getTimeRemaining cur System.out.println(cur + " " + totalTime) System.out.println System.out System System.out cur + " " + totalTime cur + " " + totalTime cur " " totalTime {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			} totalTime += quantum totalTime quantum cur.setTimeRemaining(cur.getTimeRemaining() - quantum) cur.setTimeRemaining cur cur.getTimeRemaining() - quantum cur.getTimeRemaining() cur.getTimeRemaining cur quantum q.add(cur) q.add q cur Queue<Process> q q int quantum quantum private class Process {

		String name;
		int timeRemaining;

		public Process(String name, int timeRemaining) {
			this.name = name;
			this.timeRemaining = timeRemaining;
		}

		public String getName() {
			return name;
		}

		public int getTimeRemaining() {
			return timeRemaining;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setTimeRemaining(int timeRemaining) {
			this.timeRemaining = timeRemaining;
		}

		public String toString() {
			return name;
		}
	} Process String name; name int timeRemaining; timeRemaining public Process(String name, int timeRemaining) {
			this.name = name;
			this.timeRemaining = timeRemaining;
		} Process {
			this.name = name;
			this.timeRemaining = timeRemaining;
		} this.name = name this.name this this.name name this.timeRemaining = timeRemaining this.timeRemaining this this.timeRemaining timeRemaining String name name int timeRemaining timeRemaining public String getName() {
			return name;
		} getName {
			return name;
		} return name; name public int getTimeRemaining() {
			return timeRemaining;
		} getTimeRemaining {
			return timeRemaining;
		} return timeRemaining; timeRemaining public void setName(String name) {
			this.name = name;
		} setName {
			this.name = name;
		} this.name = name this.name this this.name name String name name public void setTimeRemaining(int timeRemaining) {
			this.timeRemaining = timeRemaining;
		} setTimeRemaining {
			this.timeRemaining = timeRemaining;
		} this.timeRemaining = timeRemaining this.timeRemaining this this.timeRemaining timeRemaining int timeRemaining timeRemaining public String toString() {
			return name;
		} toString {
			return name;
		} return name; name public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int numProcesses = in.nextInt();
		int quantum = in.nextInt();
		Main r = new Main();
		Queue<Process> q = new LinkedList<Process>();

		for (int i = 1; i <= numProcesses; i++) {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		}

		performQOps(q, quantum);
	}

	public static void performQOps(Queue<Process> q, int quantum) {
		int totalTime = 0;

		while (q.size() != 0) {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		}
	}

	private class Process {

		String name;
		int timeRemaining;

		public Process(String name, int timeRemaining) {
			this.name = name;
			this.timeRemaining = timeRemaining;
		}

		public String getName() {
			return name;
		}

		public int getTimeRemaining() {
			return timeRemaining;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setTimeRemaining(int timeRemaining) {
			this.timeRemaining = timeRemaining;
		}

		public String toString() {
			return name;
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int numProcesses = in.nextInt();
		int quantum = in.nextInt();
		Main r = new Main();
		Queue<Process> q = new LinkedList<Process>();

		for (int i = 1; i <= numProcesses; i++) {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		}

		performQOps(q, quantum);
	}

	public static void performQOps(Queue<Process> q, int quantum) {
		int totalTime = 0;

		while (q.size() != 0) {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		}
	}

	private class Process {

		String name;
		int timeRemaining;

		public Process(String name, int timeRemaining) {
			this.name = name;
			this.timeRemaining = timeRemaining;
		}

		public String getName() {
			return name;
		}

		public int getTimeRemaining() {
			return timeRemaining;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setTimeRemaining(int timeRemaining) {
			this.timeRemaining = timeRemaining;
		}

		public String toString() {
			return name;
		}
	}
} Main

import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int numProcesses = in.nextInt();
		int quantum = in.nextInt();
		Main r = new Main();
		Queue<Process> q = new LinkedList<Process>();

		for (int i = 1; i <= numProcesses; i++) {
			Process p = r.new Process(in.next(), in.nextInt());
			q.add(p);
		}

		performQOps(q, quantum);
	}

	public static void performQOps(Queue<Process> q, int quantum) {
		int totalTime = 0;

		while (q.size() != 0) {

			Process cur = q.poll();

			if (cur.getTimeRemaining() <= quantum) {
				totalTime += cur.getTimeRemaining();
				System.out.println(cur + " " + totalTime);
			} else {
				totalTime += quantum;
				cur.setTimeRemaining(cur.getTimeRemaining() - quantum);
				q.add(cur);
			}
		}
	}

	private class Process {

		String name;
		int timeRemaining;

		public Process(String name, int timeRemaining) {
			this.name = name;
			this.timeRemaining = timeRemaining;
		}

		public String getName() {
			return name;
		}

		public int getTimeRemaining() {
			return timeRemaining;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setTimeRemaining(int timeRemaining) {
			this.timeRemaining = timeRemaining;
		}

		public String toString() {
			return name;
		}
	}
}

