import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static int head = 0;
	static int tail = 0;
	static Process[] queue = new Process[100005];

	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	static void enqueue(Process p) {
		if ((tail + 1) % queue.length == head) {
			System.err.println("キューが満タンです");
			return;
		}
		queue[tail] = p;
		tail = (tail + 1) % queue.length;
	}

	static Process dequeue() {
		Process ret = null;
		if (head == tail) {
			System.err.println("キューが空です");
		} else {
			ret = queue[head];
			head = (head + 1) % queue.length;
		}

		return ret;
	}

}

class Process {
	String name;
	int time;

	public 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 public class Main {
	static int head = 0;
	static int tail = 0;
	static Process[] queue = new Process[100005];

	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	static void enqueue(Process p) {
		if ((tail + 1) % queue.length == head) {
			System.err.println("キューが満タンです");
			return;
		}
		queue[tail] = p;
		tail = (tail + 1) % queue.length;
	}

	static Process dequeue() {
		Process ret = null;
		if (head == tail) {
			System.err.println("キューが空です");
		} else {
			ret = queue[head];
			head = (head + 1) % queue.length;
		}

		return ret;
	}

} Main static int head = 0; head 0 static int tail = 0; tail 0 static Process[] queue = new Process[100005]; queue new Process[100005] 100005 public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	} main {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	} try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) String nq[] = br.readLine().split(" "); nq br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(nq[0]); n Integer.parseInt(nq[0]) Integer.parseInt Integer nq[0] nq 0 int q = Integer.parseInt(nq[1]); q Integer.parseInt(nq[1]) Integer.parseInt Integer nq[1] nq 1 int total = 0; total 0 for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			} {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			} String[] tmp = br.readLine().split(" "); tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " String name = tmp[0]; name tmp[0] tmp 0 int time = Integer.parseInt(tmp[1]); time Integer.parseInt(tmp[1]) Integer.parseInt Integer tmp[1] tmp 1 Process p = new Process(name, time); p new Process(name, time) enqueue(p) enqueue p while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			} head != tail head tail {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			} Process cur = dequeue(); cur dequeue() dequeue if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				} cur.time > q cur.time cur cur.time q {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} cur.time -= q cur.time cur cur.time q total += q total q enqueue(cur) enqueue cur {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				} total += cur.time total cur.time cur cur.time System.out.println(cur.name + " " + total) System.out.println System.out System System.out cur.name + " " + total cur.name + " " + total cur.name cur cur.name " " total String[] args args static void enqueue(Process p) {
		if ((tail + 1) % queue.length == head) {
			System.err.println("キューが満タンです");
			return;
		}
		queue[tail] = p;
		tail = (tail + 1) % queue.length;
	} enqueue {
		if ((tail + 1) % queue.length == head) {
			System.err.println("キューが満タンです");
			return;
		}
		queue[tail] = p;
		tail = (tail + 1) % queue.length;
	} if ((tail + 1) % queue.length == head) {
			System.err.println("キューが満タンです");
			return;
		} (tail + 1) % queue.length == head (tail + 1) % queue.length (tail + 1) tail 1 queue.length queue queue.length head {
			System.err.println("キューが満タンです");
			return;
		} System.err.println("キューが満タンです") System.err.println System.err System System.err "キューが満タンです" return; queue[tail] = p queue[tail] queue tail p tail = (tail + 1) % queue.length tail (tail + 1) % queue.length (tail + 1) tail 1 queue.length queue queue.length Process p p static Process dequeue() {
		Process ret = null;
		if (head == tail) {
			System.err.println("キューが空です");
		} else {
			ret = queue[head];
			head = (head + 1) % queue.length;
		}

		return ret;
	} dequeue {
		Process ret = null;
		if (head == tail) {
			System.err.println("キューが空です");
		} else {
			ret = queue[head];
			head = (head + 1) % queue.length;
		}

		return ret;
	} Process ret = null; ret null if (head == tail) {
			System.err.println("キューが空です");
		} else {
			ret = queue[head];
			head = (head + 1) % queue.length;
		} head == tail head tail {
			System.err.println("キューが空です");
		} System.err.println("キューが空です") System.err.println System.err System System.err "キューが空です" {
			ret = queue[head];
			head = (head + 1) % queue.length;
		} ret = queue[head] ret queue[head] queue head head = (head + 1) % queue.length head (head + 1) % queue.length (head + 1) head 1 queue.length queue queue.length return ret; ret class Process {
	String name;
	int time;

	public Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} Process String name; name int time; time 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 public class Main {
	static int head = 0;
	static int tail = 0;
	static Process[] queue = new Process[100005];

	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	static void enqueue(Process p) {
		if ((tail + 1) % queue.length == head) {
			System.err.println("キューが満タンです");
			return;
		}
		queue[tail] = p;
		tail = (tail + 1) % queue.length;
	}

	static Process dequeue() {
		Process ret = null;
		if (head == tail) {
			System.err.println("キューが空です");
		} else {
			ret = queue[head];
			head = (head + 1) % queue.length;
		}

		return ret;
	}

} public class Main {
	static int head = 0;
	static int tail = 0;
	static Process[] queue = new Process[100005];

	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	static void enqueue(Process p) {
		if ((tail + 1) % queue.length == head) {
			System.err.println("キューが満タンです");
			return;
		}
		queue[tail] = p;
		tail = (tail + 1) % queue.length;
	}

	static Process dequeue() {
		Process ret = null;
		if (head == tail) {
			System.err.println("キューが空です");
		} else {
			ret = queue[head];
			head = (head + 1) % queue.length;
		}

		return ret;
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static int head = 0;
	static int tail = 0;
	static Process[] queue = new Process[100005];

	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String nq[] = br.readLine().split(" ");
			int n = Integer.parseInt(nq[0]);
			int q = Integer.parseInt(nq[1]);
			int total = 0;
			for (int i = 0; i < n; i++) {
				String[] tmp = br.readLine().split(" ");
				String name = tmp[0];
				int time = Integer.parseInt(tmp[1]);
				Process p = new Process(name, time);
				enqueue(p);
			}
			while (head != tail) {
				Process cur = dequeue();
				if (cur.time > q) {
					cur.time -= q;
					total += q;
					enqueue(cur);
				} else {
					total += cur.time;
					System.out.println(cur.name + " " + total);
				}

			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	static void enqueue(Process p) {
		if ((tail + 1) % queue.length == head) {
			System.err.println("キューが満タンです");
			return;
		}
		queue[tail] = p;
		tail = (tail + 1) % queue.length;
	}

	static Process dequeue() {
		Process ret = null;
		if (head == tail) {
			System.err.println("キューが空です");
		} else {
			ret = queue[head];
			head = (head + 1) % queue.length;
		}

		return ret;
	}

}

class Process {
	String name;
	int time;

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