import java.util.Scanner;

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

		Task2[] tasks = new Task2[100000];

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		}
		int time = 0;
		int head = 0;
		int tail = n;
		while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		}

	}

}

class Task2 {
	String name;
	int second;

	public Task2(String name, int second) {
		this.name = name;
		this.second = second;

	}

	public String getName() {
		return name;
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
	}

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

		Task2[] tasks = new Task2[100000];

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		}
		int time = 0;
		int head = 0;
		int tail = n;
		while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		}

	}

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

		Task2[] tasks = new Task2[100000];

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		}
		int time = 0;
		int head = 0;
		int tail = n;
		while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		}

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

		Task2[] tasks = new Task2[100000];

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		}
		int time = 0;
		int head = 0;
		int tail = n;
		while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Task2[] tasks = new Task2[100000]; tasks new Task2[100000] 100000 int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		} {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		} String name = sc.next(); name sc.next() sc.next sc int second = Integer.parseInt(sc.next()); second Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc tasks[i] = new Task2(name, second) tasks[i] tasks i new Task2(name, second) int time = 0; time 0 int head = 0; head 0 int tail = n; tail n while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		} head != tail head tail {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		} Task2 task = tasks[head]; task tasks[head] tasks head head++ head if (head == 100000) {
				head = 0;
			} head == 100000 head 100000 {
				head = 0;
			} head = 0 head 0 if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			} task.getSecond() <= q task.getSecond() task.getSecond task q {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} time += task.getSecond() time task.getSecond() task.getSecond task System.out.print(task.getName() + " ") System.out.print System.out System System.out task.getName() + " " task.getName() task.getName task " " System.out.println(time) System.out.println System.out System System.out time {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			} time += q time q task.setSecond(task.getSecond() - q) task.setSecond task task.getSecond() - q task.getSecond() task.getSecond task q tasks[tail] = task tasks[tail] tasks tail task tail++ tail if (tail == 100000) {
					tail = 0;

				} tail == 100000 tail 100000 {
					tail = 0;

				} tail = 0 tail 0 String[] args args class Task2 {
	String name;
	int second;

	public Task2(String name, int second) {
		this.name = name;
		this.second = second;

	}

	public String getName() {
		return name;
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
	}

} Task2 String name; name int second; second public Task2(String name, int second) {
		this.name = name;
		this.second = second;

	} Task2 {
		this.name = name;
		this.second = second;

	} this.name = name this.name this this.name name this.second = second this.second this this.second second String name name int second second public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public int getSecond() {
		return second;
	} getSecond {
		return second;
	} return second; second public void setSecond(int second) {
		this.second = second;
	} setSecond {
		this.second = second;
	} this.second = second this.second this this.second second int second second public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		Task2[] tasks = new Task2[100000];

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		}
		int time = 0;
		int head = 0;
		int tail = n;
		while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		}

	}

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

		Task2[] tasks = new Task2[100000];

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		}
		int time = 0;
		int head = 0;
		int tail = n;
		while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		}

	}

} Main
import java.util.Scanner;

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

		Task2[] tasks = new Task2[100000];

		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int second = Integer.parseInt(sc.next());
			tasks[i] = new Task2(name, second);
		}
		int time = 0;
		int head = 0;
		int tail = n;
		while (head != tail) {
			Task2 task = tasks[head];
			head++;
			if (head == 100000) {
				head = 0;
			}
			if (task.getSecond() <= q) {
				time += task.getSecond();
				System.out.print(task.getName() + " ");
				System.out.println(time);

			} else {
				time += q;
				task.setSecond(task.getSecond() - q);
				tasks[tail] = task;
				tail++;
				if (tail == 100000) {
					tail = 0;

				}
			}

		}

	}

}

class Task2 {
	String name;
	int second;

	public Task2(String name, int second) {
		this.name = name;
		this.second = second;

	}

	public String getName() {
		return name;
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
	}

}