import java.io.*;
import java.util.*;

class Main {
	final static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	final static StringBuilder out = new StringBuilder();
	public static void main(String[] Args) throws IOException {
		Queue<Process> p = new ArrayDeque<Process>();
		Process work;
		int elapse = 0;
		String[] in = br.readLine().split("\\s+");
		int n = Integer.parseInt(in[0]);
		int q = Integer.parseInt(in[1]);
		for (int i = 0; i < n; i++) {
			work = new Process(br.readLine());
			p.add(work);
		}
		while ((work = p.poll()) != null) {
			if (work.time <= q) {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} else {
				work.time -= q;
				elapse += q;
				p.add(work);
			}
		}
		System.out.print(out);
	}
}

class Process {
	String name;
	int time;
	public Process(String str) {
		String[] in = str.split("\\s+");
		name = in[0];
		time = Integer.parseInt(in[1]);
	}
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} import java.io.*; io.* java import java.util.*; util.* java class Main {
	final static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	final static StringBuilder out = new StringBuilder();
	public static void main(String[] Args) throws IOException {
		Queue<Process> p = new ArrayDeque<Process>();
		Process work;
		int elapse = 0;
		String[] in = br.readLine().split("\\s+");
		int n = Integer.parseInt(in[0]);
		int q = Integer.parseInt(in[1]);
		for (int i = 0; i < n; i++) {
			work = new Process(br.readLine());
			p.add(work);
		}
		while ((work = p.poll()) != null) {
			if (work.time <= q) {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} else {
				work.time -= q;
				elapse += q;
				p.add(work);
			}
		}
		System.out.print(out);
	}
} Main final static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in)); br new BufferedReader(new InputStreamReader(
			System.in)) final static StringBuilder out = new StringBuilder(); out new StringBuilder() public static void main(String[] Args) throws IOException {
		Queue<Process> p = new ArrayDeque<Process>();
		Process work;
		int elapse = 0;
		String[] in = br.readLine().split("\\s+");
		int n = Integer.parseInt(in[0]);
		int q = Integer.parseInt(in[1]);
		for (int i = 0; i < n; i++) {
			work = new Process(br.readLine());
			p.add(work);
		}
		while ((work = p.poll()) != null) {
			if (work.time <= q) {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} else {
				work.time -= q;
				elapse += q;
				p.add(work);
			}
		}
		System.out.print(out);
	} main {
		Queue<Process> p = new ArrayDeque<Process>();
		Process work;
		int elapse = 0;
		String[] in = br.readLine().split("\\s+");
		int n = Integer.parseInt(in[0]);
		int q = Integer.parseInt(in[1]);
		for (int i = 0; i < n; i++) {
			work = new Process(br.readLine());
			p.add(work);
		}
		while ((work = p.poll()) != null) {
			if (work.time <= q) {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} else {
				work.time -= q;
				elapse += q;
				p.add(work);
			}
		}
		System.out.print(out);
	} Queue<Process> p = new ArrayDeque<Process>(); p new ArrayDeque<Process>() Process work; work int elapse = 0; elapse 0 String[] in = br.readLine().split("\\s+"); in br.readLine().split("\\s+") br.readLine().split br.readLine() br.readLine br "\\s+" int n = Integer.parseInt(in[0]); n Integer.parseInt(in[0]) Integer.parseInt Integer in[0] in 0 int q = Integer.parseInt(in[1]); q Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 for (int i = 0; i < n; i++) {
			work = new Process(br.readLine());
			p.add(work);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			work = new Process(br.readLine());
			p.add(work);
		} {
			work = new Process(br.readLine());
			p.add(work);
		} work = new Process(br.readLine()) work new Process(br.readLine()) p.add(work) p.add p work while ((work = p.poll()) != null) {
			if (work.time <= q) {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} else {
				work.time -= q;
				elapse += q;
				p.add(work);
			}
		} (work = p.poll()) != null (work = p.poll()) work p.poll() p.poll p null {
			if (work.time <= q) {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} else {
				work.time -= q;
				elapse += q;
				p.add(work);
			}
		} if (work.time <= q) {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} else {
				work.time -= q;
				elapse += q;
				p.add(work);
			} work.time <= q work.time work work.time q {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} elapse += work.time elapse work.time work work.time out.append(work.name).append(' ').append(elapse).append('\n') out.append(work.name).append(' ').append(elapse).append out.append(work.name).append(' ').append(elapse) out.append(work.name).append(' ').append out.append(work.name).append(' ') out.append(work.name).append out.append(work.name) out.append out work.name work work.name ' ' elapse '\n' {
				work.time -= q;
				elapse += q;
				p.add(work);
			} work.time -= q work.time work work.time q elapse += q elapse q p.add(work) p.add p work System.out.print(out) System.out.print System.out System System.out out String[] Args Args class Process {
	String name;
	int time;
	public Process(String str) {
		String[] in = str.split("\\s+");
		name = in[0];
		time = Integer.parseInt(in[1]);
	}
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} Process String name; name int time; time public Process(String str) {
		String[] in = str.split("\\s+");
		name = in[0];
		time = Integer.parseInt(in[1]);
	} Process {
		String[] in = str.split("\\s+");
		name = in[0];
		time = Integer.parseInt(in[1]);
	} String[] in = str.split("\\s+"); in str.split("\\s+") str.split str "\\s+" name = in[0] name in[0] in 0 time = Integer.parseInt(in[1]) time Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 String str str public 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
import java.io.*;
import java.util.*;

class Main {
	final static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	final static StringBuilder out = new StringBuilder();
	public static void main(String[] Args) throws IOException {
		Queue<Process> p = new ArrayDeque<Process>();
		Process work;
		int elapse = 0;
		String[] in = br.readLine().split("\\s+");
		int n = Integer.parseInt(in[0]);
		int q = Integer.parseInt(in[1]);
		for (int i = 0; i < n; i++) {
			work = new Process(br.readLine());
			p.add(work);
		}
		while ((work = p.poll()) != null) {
			if (work.time <= q) {
				elapse += work.time;
				out.append(work.name).append(' ').append(elapse).append('\n');
			} else {
				work.time -= q;
				elapse += q;
				p.add(work);
			}
		}
		System.out.print(out);
	}
}

class Process {
	String name;
	int time;
	public Process(String str) {
		String[] in = str.split("\\s+");
		name = in[0];
		time = Integer.parseInt(in[1]);
	}
	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
}