import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] str = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);

		int q = Integer.parseInt(str[1]);

		Deque<String> dq = new ArrayDeque<>();

		for (int i = 0; i < n; i++) {
			String[] name_time = br.readLine().split(" ");

			dq.offerLast(name_time[0]);
			dq.offerLast(name_time[1]);

		}

		int[] total_time = new int[n];
		String[] name = new String[n];

		int a = 0;
		int p = 0;
		while (!(dq.isEmpty())) {

			String Now_name = dq.pollFirst();

			int now_time = Integer.parseInt(dq.pollFirst());
			/*
			 * System.out.println(Now_name+" "+now_time);
			 */
			if (now_time - q > 0) {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} else {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			}

		}

		for (int i = 0; i < n; i++) {
			System.out.println(name[i] + " " + total_time[i]);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] str = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);

		int q = Integer.parseInt(str[1]);

		Deque<String> dq = new ArrayDeque<>();

		for (int i = 0; i < n; i++) {
			String[] name_time = br.readLine().split(" ");

			dq.offerLast(name_time[0]);
			dq.offerLast(name_time[1]);

		}

		int[] total_time = new int[n];
		String[] name = new String[n];

		int a = 0;
		int p = 0;
		while (!(dq.isEmpty())) {

			String Now_name = dq.pollFirst();

			int now_time = Integer.parseInt(dq.pollFirst());
			/*
			 * System.out.println(Now_name+" "+now_time);
			 */
			if (now_time - q > 0) {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} else {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			}

		}

		for (int i = 0; i < n; i++) {
			System.out.println(name[i] + " " + total_time[i]);
		}
	}
} Main public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] str = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);

		int q = Integer.parseInt(str[1]);

		Deque<String> dq = new ArrayDeque<>();

		for (int i = 0; i < n; i++) {
			String[] name_time = br.readLine().split(" ");

			dq.offerLast(name_time[0]);
			dq.offerLast(name_time[1]);

		}

		int[] total_time = new int[n];
		String[] name = new String[n];

		int a = 0;
		int p = 0;
		while (!(dq.isEmpty())) {

			String Now_name = dq.pollFirst();

			int now_time = Integer.parseInt(dq.pollFirst());
			/*
			 * System.out.println(Now_name+" "+now_time);
			 */
			if (now_time - q > 0) {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} else {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			}

		}

		for (int i = 0; i < n; i++) {
			System.out.println(name[i] + " " + total_time[i]);
		}
	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] str = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);

		int q = Integer.parseInt(str[1]);

		Deque<String> dq = new ArrayDeque<>();

		for (int i = 0; i < n; i++) {
			String[] name_time = br.readLine().split(" ");

			dq.offerLast(name_time[0]);
			dq.offerLast(name_time[1]);

		}

		int[] total_time = new int[n];
		String[] name = new String[n];

		int a = 0;
		int p = 0;
		while (!(dq.isEmpty())) {

			String Now_name = dq.pollFirst();

			int now_time = Integer.parseInt(dq.pollFirst());
			/*
			 * System.out.println(Now_name+" "+now_time);
			 */
			if (now_time - q > 0) {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} else {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			}

		}

		for (int i = 0; i < n; i++) {
			System.out.println(name[i] + " " + total_time[i]);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int q = Integer.parseInt(str[1]); q Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 Deque<String> dq = new ArrayDeque<>(); dq new ArrayDeque<>() for (int i = 0; i < n; i++) {
			String[] name_time = br.readLine().split(" ");

			dq.offerLast(name_time[0]);
			dq.offerLast(name_time[1]);

		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String[] name_time = br.readLine().split(" ");

			dq.offerLast(name_time[0]);
			dq.offerLast(name_time[1]);

		} {
			String[] name_time = br.readLine().split(" ");

			dq.offerLast(name_time[0]);
			dq.offerLast(name_time[1]);

		} String[] name_time = br.readLine().split(" "); name_time br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " dq.offerLast(name_time[0]) dq.offerLast dq name_time[0] name_time 0 dq.offerLast(name_time[1]) dq.offerLast dq name_time[1] name_time 1 int[] total_time = new int[n]; total_time new int[n] n String[] name = new String[n]; name new String[n] n int a = 0; a 0 int p = 0; p 0 while (!(dq.isEmpty())) {

			String Now_name = dq.pollFirst();

			int now_time = Integer.parseInt(dq.pollFirst());
			/*
			 * System.out.println(Now_name+" "+now_time);
			 */
			if (now_time - q > 0) {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} else {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			}

		} !(dq.isEmpty()) (dq.isEmpty()) dq.isEmpty dq {

			String Now_name = dq.pollFirst();

			int now_time = Integer.parseInt(dq.pollFirst());
			/*
			 * System.out.println(Now_name+" "+now_time);
			 */
			if (now_time - q > 0) {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} else {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			}

		} String Now_name = dq.pollFirst(); Now_name dq.pollFirst() dq.pollFirst dq int now_time = Integer.parseInt(dq.pollFirst()); now_time Integer.parseInt(dq.pollFirst()) Integer.parseInt Integer dq.pollFirst() dq.pollFirst dq if (now_time - q > 0) {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} else {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			} now_time - q > 0 now_time - q now_time q 0 {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} dq.offerLast(Now_name) dq.offerLast dq Now_name dq.offerLast(String.valueOf(now_time - q)) dq.offerLast dq String.valueOf(now_time - q) String.valueOf String now_time - q now_time q a += q a q {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			} a += now_time a now_time total_time[p] = a total_time[p] total_time p a name[p] = Now_name name[p] name p Now_name p++ p for (int i = 0; i < n; i++) {
			System.out.println(name[i] + " " + total_time[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			System.out.println(name[i] + " " + total_time[i]);
		} {
			System.out.println(name[i] + " " + total_time[i]);
		} System.out.println(name[i] + " " + total_time[i]) System.out.println System.out System System.out name[i] + " " + total_time[i] name[i] + " " + total_time[i] name[i] name i " " total_time[i] total_time i String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] str = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);

		int q = Integer.parseInt(str[1]);

		Deque<String> dq = new ArrayDeque<>();

		for (int i = 0; i < n; i++) {
			String[] name_time = br.readLine().split(" ");

			dq.offerLast(name_time[0]);
			dq.offerLast(name_time[1]);

		}

		int[] total_time = new int[n];
		String[] name = new String[n];

		int a = 0;
		int p = 0;
		while (!(dq.isEmpty())) {

			String Now_name = dq.pollFirst();

			int now_time = Integer.parseInt(dq.pollFirst());
			/*
			 * System.out.println(Now_name+" "+now_time);
			 */
			if (now_time - q > 0) {
				dq.offerLast(Now_name);
				dq.offerLast(String.valueOf(now_time - q));

				a += q;
			} else {
				a += now_time;
				total_time[p] = a;
				name[p] = Now_name;

				p++;
			}

		}

		for (int i = 0; i < n; i++) {
			System.out.println(name[i] + " " + total_time[i]);
		}
	}
}