import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> names = new LinkedList<>();
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			names.add(sc.next());
			queue.add(sc.nextInt());
		}
		while (queue.size() > 0) {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		}
	}
}
 import java.util.Deque; Deque java.util import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> names = new LinkedList<>();
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			names.add(sc.next());
			queue.add(sc.nextInt());
		}
		while (queue.size() > 0) {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> names = new LinkedList<>();
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			names.add(sc.next());
			queue.add(sc.nextInt());
		}
		while (queue.size() > 0) {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> names = new LinkedList<>();
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			names.add(sc.next());
			queue.add(sc.nextInt());
		}
		while (queue.size() > 0) {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Deque<Integer> queue = new LinkedList<>(); queue new LinkedList<>() Deque<String> names = new LinkedList<>(); names new LinkedList<>() int time = 0; time 0 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc for (int i = 0; i < n; i++) {
			names.add(sc.next());
			queue.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			names.add(sc.next());
			queue.add(sc.nextInt());
		} {
			names.add(sc.next());
			queue.add(sc.nextInt());
		} names.add(sc.next()) names.add names sc.next() sc.next sc queue.add(sc.nextInt()) queue.add queue sc.nextInt() sc.nextInt sc while (queue.size() > 0) {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		} queue.size() > 0 queue.size() queue.size queue 0 {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		} queue.addLast(queue.poll() - q) queue.addLast queue queue.poll() - q queue.poll() queue.poll queue q names.addLast(names.poll()) names.addLast names names.poll() names.poll names time += q time q if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			} queue.peekLast() <= 0 queue.peekLast() queue.peekLast queue 0 {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			} time += queue.pollLast() time queue.pollLast() queue.pollLast queue System.out.println(names.pollLast() + " " + time) System.out.println System.out System System.out names.pollLast() + " " + time names.pollLast() + " " + time names.pollLast() names.pollLast names " " time String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> names = new LinkedList<>();
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			names.add(sc.next());
			queue.add(sc.nextInt());
		}
		while (queue.size() > 0) {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> names = new LinkedList<>();
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			names.add(sc.next());
			queue.add(sc.nextInt());
		}
		while (queue.size() > 0) {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		}
	}
} Main
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> queue = new LinkedList<>();
		Deque<String> names = new LinkedList<>();
		int time = 0;
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			names.add(sc.next());
			queue.add(sc.nextInt());
		}
		while (queue.size() > 0) {
			queue.addLast(queue.poll() - q);
			names.addLast(names.poll());
			time += q;
			if (queue.peekLast() <= 0) {
				time += queue.pollLast();
				System.out.println(names.pollLast() + " " + time);
			}
		}
	}
}

