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);

		String[] S = sc.nextLine().split(" ");
		int n = Integer.parseInt(S[0]);
		int quantum = Integer.parseInt(S[1]);

		Queue<Node> queue = new ArrayDeque<Node>();

		for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		}

		long count = 0;

		while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		}

		sc.close();
	}
}

class Node {
	private String name;
	private int time;

	public Node(String name, int time) {
		this.name = name;
		this.time = time;
	}

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

	public String getName() {
		return this.name;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public int getTime() {
		return this.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);

		String[] S = sc.nextLine().split(" ");
		int n = Integer.parseInt(S[0]);
		int quantum = Integer.parseInt(S[1]);

		Queue<Node> queue = new ArrayDeque<Node>();

		for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		}

		long count = 0;

		while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		}

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

		String[] S = sc.nextLine().split(" ");
		int n = Integer.parseInt(S[0]);
		int quantum = Integer.parseInt(S[1]);

		Queue<Node> queue = new ArrayDeque<Node>();

		for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		}

		long count = 0;

		while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		}

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

		String[] S = sc.nextLine().split(" ");
		int n = Integer.parseInt(S[0]);
		int quantum = Integer.parseInt(S[1]);

		Queue<Node> queue = new ArrayDeque<Node>();

		for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		}

		long count = 0;

		while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		}

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] S = sc.nextLine().split(" "); S sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int n = Integer.parseInt(S[0]); n Integer.parseInt(S[0]) Integer.parseInt Integer S[0] S 0 int quantum = Integer.parseInt(S[1]); quantum Integer.parseInt(S[1]) Integer.parseInt Integer S[1] S 1 Queue<Node> queue = new ArrayDeque<Node>(); queue new ArrayDeque<Node>() for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		} {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		} S = sc.nextLine().split(" ") S sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " Node node = new Node(S[0], Integer.parseInt(S[1])); node new Node(S[0], Integer.parseInt(S[1])) queue.offer(node) queue.offer queue node long count = 0; count 0 while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		} Node tmp = queue.poll(); tmp queue.poll() queue.poll queue if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			} tmp.getTime() > quantum tmp.getTime() tmp.getTime tmp quantum {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} count += quantum count quantum tmp.setTime(tmp.getTime() - quantum) tmp.setTime tmp tmp.getTime() - quantum tmp.getTime() tmp.getTime tmp quantum queue.offer(tmp) queue.offer queue tmp {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			} count += tmp.getTime() count tmp.getTime() tmp.getTime tmp System.out.printf("%s %d", tmp.getName(), count) System.out.printf System.out System System.out "%s %d" tmp.getName() tmp.getName tmp count System.out.println("") System.out.println System.out System System.out "" sc.close() sc.close sc String[] args args class Node {
	private String name;
	private int time;

	public Node(String name, int time) {
		this.name = name;
		this.time = time;
	}

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

	public String getName() {
		return this.name;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public int getTime() {
		return this.time;
	}
} Node private String name; name private int time; time public Node(String name, int time) {
		this.name = name;
		this.time = time;
	} Node {
		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 void setName(String name) {
		this.name = name;
	} setName {
		this.name = name;
	} this.name = name this.name this this.name name String name name public String getName() {
		return this.name;
	} getName {
		return this.name;
	} return this.name; this.name this this.name public void setTime(int time) {
		this.time = time;
	} setTime {
		this.time = time;
	} this.time = time this.time this this.time time int time time public int getTime() {
		return this.time;
	} getTime {
		return this.time;
	} return this.time; this.time this this.time public class Main {

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

		String[] S = sc.nextLine().split(" ");
		int n = Integer.parseInt(S[0]);
		int quantum = Integer.parseInt(S[1]);

		Queue<Node> queue = new ArrayDeque<Node>();

		for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		}

		long count = 0;

		while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		}

		sc.close();
	}
} public class Main {

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

		String[] S = sc.nextLine().split(" ");
		int n = Integer.parseInt(S[0]);
		int quantum = Integer.parseInt(S[1]);

		Queue<Node> queue = new ArrayDeque<Node>();

		for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		}

		long count = 0;

		while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		}

		sc.close();
	}
} 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);

		String[] S = sc.nextLine().split(" ");
		int n = Integer.parseInt(S[0]);
		int quantum = Integer.parseInt(S[1]);

		Queue<Node> queue = new ArrayDeque<Node>();

		for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		}

		long count = 0;

		while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		}

		sc.close();
	}
}

class Node {
	private String name;
	private int time;

	public Node(String name, int time) {
		this.name = name;
		this.time = time;
	}

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

	public String getName() {
		return this.name;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public int getTime() {
		return this.time;
	}
}

