import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		int n, q, t;
		int t_sum = 0;
		String pros;
		Deque<String> name = new ArrayDeque<>();
		Deque<Integer> time = new ArrayDeque<>();

		Scanner sc = new Scanner(System.in);

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

		for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		}

		while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		}
	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]) {
		int n, q, t;
		int t_sum = 0;
		String pros;
		Deque<String> name = new ArrayDeque<>();
		Deque<Integer> time = new ArrayDeque<>();

		Scanner sc = new Scanner(System.in);

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

		for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		}

		while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		}
	}
} Main public static void main(String args[]) {
		int n, q, t;
		int t_sum = 0;
		String pros;
		Deque<String> name = new ArrayDeque<>();
		Deque<Integer> time = new ArrayDeque<>();

		Scanner sc = new Scanner(System.in);

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

		for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		}

		while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		}
	} main {
		int n, q, t;
		int t_sum = 0;
		String pros;
		Deque<String> name = new ArrayDeque<>();
		Deque<Integer> time = new ArrayDeque<>();

		Scanner sc = new Scanner(System.in);

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

		for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		}

		while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		}
	} int n n q q t; t int t_sum = 0; t_sum 0 String pros; pros Deque<String> name = new ArrayDeque<>(); name new ArrayDeque<>() Deque<Integer> time = new ArrayDeque<>(); time new ArrayDeque<>() Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt() q sc.nextInt() sc.nextInt sc for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		} {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		} name.offerLast(sc.next()) name.offerLast name sc.next() sc.next sc time.offerLast(sc.nextInt()) time.offerLast time sc.nextInt() sc.nextInt sc while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		} time.size() != 0 time.size() time.size time 0 {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		} t = time.poll() t time.poll() time.poll time if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			} t <= q t q {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} t_sum += t t_sum t pros = name.poll() pros name.poll() name.poll name System.out.println(pros + " " + t_sum) System.out.println System.out System System.out pros + " " + t_sum pros + " " + t_sum pros " " t_sum {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			} t_sum += q t_sum q time.offerLast(t - q) time.offerLast time t - q t q name.offerLast(name.poll()) name.offerLast name name.poll() name.poll name String args[] args public class Main {
	public static void main(String args[]) {
		int n, q, t;
		int t_sum = 0;
		String pros;
		Deque<String> name = new ArrayDeque<>();
		Deque<Integer> time = new ArrayDeque<>();

		Scanner sc = new Scanner(System.in);

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

		for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		}

		while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		}
	}
} public class Main {
	public static void main(String args[]) {
		int n, q, t;
		int t_sum = 0;
		String pros;
		Deque<String> name = new ArrayDeque<>();
		Deque<Integer> time = new ArrayDeque<>();

		Scanner sc = new Scanner(System.in);

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

		for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		}

		while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		}
	}
} Main
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		int n, q, t;
		int t_sum = 0;
		String pros;
		Deque<String> name = new ArrayDeque<>();
		Deque<Integer> time = new ArrayDeque<>();

		Scanner sc = new Scanner(System.in);

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

		for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		}

		while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		}
	}
}