import java.util.ArrayList;
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int q = sc.nextInt();
		int total = 0;
		int count = 0;

		ArrayList<Integer> time = new ArrayList<>();
		ArrayList<String> name = new ArrayList<>();

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

		while (time.size() != 0) {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		}

	}
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {

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

		int n = sc.nextInt();
		int q = sc.nextInt();
		int total = 0;
		int count = 0;

		ArrayList<Integer> time = new ArrayList<>();
		ArrayList<String> name = new ArrayList<>();

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

		while (time.size() != 0) {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		}

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

		int n = sc.nextInt();
		int q = sc.nextInt();
		int total = 0;
		int count = 0;

		ArrayList<Integer> time = new ArrayList<>();
		ArrayList<String> name = new ArrayList<>();

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

		while (time.size() != 0) {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		}

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

		int n = sc.nextInt();
		int q = sc.nextInt();
		int total = 0;
		int count = 0;

		ArrayList<Integer> time = new ArrayList<>();
		ArrayList<String> name = new ArrayList<>();

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

		while (time.size() != 0) {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc int total = 0; total 0 int count = 0; count 0 ArrayList<Integer> time = new ArrayList<>(); time new ArrayList<>() ArrayList<String> name = new ArrayList<>(); name new ArrayList<>() for (int i = 0; i < n; i++) {
			name.add(sc.next());
			time.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			name.add(sc.next());
			time.add(sc.nextInt());
		} {
			name.add(sc.next());
			time.add(sc.nextInt());
		} name.add(sc.next()) name.add name sc.next() sc.next sc time.add(sc.nextInt()) time.add time sc.nextInt() sc.nextInt sc while (time.size() != 0) {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		} time.size() != 0 time.size() time.size time 0 {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		} if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			} time.get(count) <= q time.get(count) time.get time count q {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} total += time.get(count) total time.get(count) time.get time count System.out.printf("%s %d\n", name.get(count), total) System.out.printf System.out System System.out "%s %d\n" name.get(count) name.get name count total time.remove(count) time.remove time count name.remove(count) name.remove name count count = count >= name.size() ? 0 : count count count >= name.size() ? 0 : count count >= name.size() count name.size() name.size name 0 count {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			} total += q total q time.set(count, time.get(count) - q) time.set time count time.get(count) - q time.get(count) time.get time count q count = ++count >= name.size() ? 0 : count count ++count >= name.size() ? 0 : count ++count >= name.size() ++count count name.size() name.size name 0 count String[] args args public class Main {

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

		int n = sc.nextInt();
		int q = sc.nextInt();
		int total = 0;
		int count = 0;

		ArrayList<Integer> time = new ArrayList<>();
		ArrayList<String> name = new ArrayList<>();

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

		while (time.size() != 0) {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		}

	}
} public class Main {

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

		int n = sc.nextInt();
		int q = sc.nextInt();
		int total = 0;
		int count = 0;

		ArrayList<Integer> time = new ArrayList<>();
		ArrayList<String> name = new ArrayList<>();

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

		while (time.size() != 0) {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		}

	}
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int q = sc.nextInt();
		int total = 0;
		int count = 0;

		ArrayList<Integer> time = new ArrayList<>();
		ArrayList<String> name = new ArrayList<>();

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

		while (time.size() != 0) {
			if (time.get(count) <= q) {
				total += time.get(count);
				System.out.printf("%s %d\n", name.get(count), total);
				time.remove(count);
				name.remove(count);
				count = count >= name.size() ? 0 : count;
			} else {
				total += q;
				time.set(count, time.get(count) - q);
				count = ++count >= name.size() ? 0 : count;

			}

		}

	}
}
