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

import static java.lang.Integer.parseInt;

/**
 * Elementary data structures - Queue
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// read
		line = br.readLine();
		int n = parseInt(line.substring(0, line.indexOf(' ')));
		int q = parseInt(line.substring(line.indexOf(' ') + 1));
		Deque<Process> queue = new ArrayDeque<Process>();

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		}

		// solve
		int elapse = 0;
		StringBuilder sb = new StringBuilder();
		while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		}
		System.out.print(sb);
	} //end main
}

class Process {
	String name;
	int time;

	Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} 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 import static java.lang.Integer.parseInt; import static java.lang.Integer.parseInt; import static java.lang.Integer.parseInt; public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// read
		line = br.readLine();
		int n = parseInt(line.substring(0, line.indexOf(' ')));
		int q = parseInt(line.substring(line.indexOf(' ') + 1));
		Deque<Process> queue = new ArrayDeque<Process>();

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		}

		// solve
		int elapse = 0;
		StringBuilder sb = new StringBuilder();
		while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		}
		System.out.print(sb);
	} //end main
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// read
		line = br.readLine();
		int n = parseInt(line.substring(0, line.indexOf(' ')));
		int q = parseInt(line.substring(line.indexOf(' ') + 1));
		Deque<Process> queue = new ArrayDeque<Process>();

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		}

		// solve
		int elapse = 0;
		StringBuilder sb = new StringBuilder();
		while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		}
		System.out.print(sb);
	} //end main main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// read
		line = br.readLine();
		int n = parseInt(line.substring(0, line.indexOf(' ')));
		int q = parseInt(line.substring(line.indexOf(' ') + 1));
		Deque<Process> queue = new ArrayDeque<Process>();

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		}

		// solve
		int elapse = 0;
		StringBuilder sb = new StringBuilder();
		while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		}
		System.out.print(sb);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line; line line = br.readLine() line br.readLine() br.readLine br int n = parseInt(line.substring(0, line.indexOf(' '))); n parseInt(line.substring(0, line.indexOf(' '))) parseInt line.substring(0, line.indexOf(' ')) line.substring line 0 line.indexOf(' ') line.indexOf line ' ' int q = parseInt(line.substring(line.indexOf(' ') + 1)); q parseInt(line.substring(line.indexOf(' ') + 1)) parseInt line.substring(line.indexOf(' ') + 1) line.substring line line.indexOf(' ') + 1 line.indexOf(' ') line.indexOf line ' ' 1 Deque<Process> queue = new ArrayDeque<Process>(); queue new ArrayDeque<Process>() for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		} {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		} line = br.readLine() line br.readLine() br.readLine br String name = line.substring(0, line.indexOf(' ')); name line.substring(0, line.indexOf(' ')) line.substring line 0 line.indexOf(' ') line.indexOf line ' ' int time = parseInt(line.substring(line.indexOf(' ') + 1)); time parseInt(line.substring(line.indexOf(' ') + 1)) parseInt line.substring(line.indexOf(' ') + 1) line.substring line line.indexOf(' ') + 1 line.indexOf(' ') line.indexOf line ' ' 1 queue.offer(new Process(name, time)) queue.offer queue new Process(name, time) int elapse = 0; elapse 0 StringBuilder sb = new StringBuilder(); sb new StringBuilder() while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		} Process p = queue.poll(); p queue.poll() queue.poll queue if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			} p.time <= q p.time p p.time q {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} elapse += p.time elapse p.time p p.time sb.append(p.name + " " + elapse + "\n") sb.append sb p.name + " " + elapse + "\n" elapse p.name + " " + elapse + "\n" p.name p p.name " " elapse "\n" {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			} p.time -= q p.time p p.time q elapse += q elapse q queue.offer(p) queue.offer queue p System.out.print(sb) System.out.print System.out System System.out sb String[] args args class Process {
	String name;
	int time;

	Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} Process String name; name int time; time Process(String name, int time) {
		this.name = name;
		this.time = time;
	} Process {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// read
		line = br.readLine();
		int n = parseInt(line.substring(0, line.indexOf(' ')));
		int q = parseInt(line.substring(line.indexOf(' ') + 1));
		Deque<Process> queue = new ArrayDeque<Process>();

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		}

		// solve
		int elapse = 0;
		StringBuilder sb = new StringBuilder();
		while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		}
		System.out.print(sb);
	} //end main
} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// read
		line = br.readLine();
		int n = parseInt(line.substring(0, line.indexOf(' ')));
		int q = parseInt(line.substring(line.indexOf(' ') + 1));
		Deque<Process> queue = new ArrayDeque<Process>();

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		}

		// solve
		int elapse = 0;
		StringBuilder sb = new StringBuilder();
		while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		}
		System.out.print(sb);
	} //end main
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

import static java.lang.Integer.parseInt;

/**
 * Elementary data structures - Queue
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// read
		line = br.readLine();
		int n = parseInt(line.substring(0, line.indexOf(' ')));
		int q = parseInt(line.substring(line.indexOf(' ') + 1));
		Deque<Process> queue = new ArrayDeque<Process>();

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		}

		// solve
		int elapse = 0;
		StringBuilder sb = new StringBuilder();
		while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		}
		System.out.print(sb);
	} //end main
}

class Process {
	String name;
	int time;

	Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
}