import java.io.IOException;
import java.util.Scanner;
public class Main {

	private static int max; // 要素の数
	private static int run; // 処理速度
	private static Object q[]; // queue
	private static String end[]; // 処理済み
	private static int count; // 処理済み数
	private static int front; // 先頭
	private static int rear; // 末尾
	private static int time; // 合計処理時間

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

		max = sc.nextInt();
		run = sc.nextInt();

		q = new Object[max+1];
		front = rear = count = time = 0;
		end = new String[max];

		for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		}

		while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		}

		show();

		sc.close();
	}

	public static void show() {
		for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		}
	}

	/*
	 * ポインタの位置
	 */
	public static int next(int a) {
		return (a + 1) % max;
	}

	/*
	 * 入れる
	 */
	public static void enqueue(Object x) {
/*		if(next(rear) == front) {
			throw new IllegalStateException();
		}*/
		q[rear] = x;
		rear = next(rear);
	}

	/*
	 * 取り出す
	 */
	public static Object dequeue() {
		Object x = q[front];
		q[front] = null;
		front = next(front);
		return x;
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {

	private static int max; // 要素の数
	private static int run; // 処理速度
	private static Object q[]; // queue
	private static String end[]; // 処理済み
	private static int count; // 処理済み数
	private static int front; // 先頭
	private static int rear; // 末尾
	private static int time; // 合計処理時間

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

		max = sc.nextInt();
		run = sc.nextInt();

		q = new Object[max+1];
		front = rear = count = time = 0;
		end = new String[max];

		for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		}

		while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		}

		show();

		sc.close();
	}

	public static void show() {
		for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		}
	}

	/*
	 * ポインタの位置
	 */
	public static int next(int a) {
		return (a + 1) % max;
	}

	/*
	 * 入れる
	 */
	public static void enqueue(Object x) {
/*		if(next(rear) == front) {
			throw new IllegalStateException();
		}*/
		q[rear] = x;
		rear = next(rear);
	}

	/*
	 * 取り出す
	 */
	public static Object dequeue() {
		Object x = q[front];
		q[front] = null;
		front = next(front);
		return x;
	}
} Main private static int max; // 要素の数 max private static int run; // 処理速度 run private static Object q[]; // queue q private static String end[]; // 処理済み end private static int count; // 処理済み数 count private static int front; // 先頭 front private static int rear; // 末尾 rear private static int time; // 合計処理時間 time public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		max = sc.nextInt();
		run = sc.nextInt();

		q = new Object[max+1];
		front = rear = count = time = 0;
		end = new String[max];

		for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		}

		while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		}

		show();

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

		max = sc.nextInt();
		run = sc.nextInt();

		q = new Object[max+1];
		front = rear = count = time = 0;
		end = new String[max];

		for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		}

		while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		}

		show();

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) max = sc.nextInt() max sc.nextInt() sc.nextInt sc run = sc.nextInt() run sc.nextInt() sc.nextInt sc q = new Object[max+1] q new Object[max+1] max+1 max 1 front = rear = count = time = 0 front rear = count = time = 0 rear count = time = 0 count time = 0 time 0 end = new String[max] end new String[max] max for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		} int i=0; int i=0; i 0 i<max i max i++ i++ i {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		} {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		} String a = sc.next(); a sc.next() sc.next sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc enqueue(a + " " +b) enqueue a + " " +b a + " " +b a " " b while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		} true {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		} String[] line = dequeue().toString().split(" "); line dequeue().toString().split(" ") dequeue().toString().split dequeue().toString() dequeue().toString dequeue() dequeue " " int x = Integer.parseInt(line[1]); x Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			} x <= run x run {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			} time += x time x end[count++] = line[0] + " " + Integer.toString(time) end[count++] end count++ count line[0] + " " + Integer.toString(time) line[0] + " " + Integer.toString(time) line[0] line 0 " " Integer.toString(time) Integer.toString Integer time {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			} line[1] = Integer.toString(x - run) line[1] line 1 Integer.toString(x - run) Integer.toString Integer x - run x run enqueue(line[0] + " " + line[1]) enqueue line[0] + " " + line[1] line[0] + " " + line[1] line[0] line 0 " " line[1] line 1 time += run time run if(count == max) {
				break;
			} count == max count max {
				break;
			} break; show() show sc.close() sc.close sc String[] args args public static void show() {
		for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		}
	} show {
		for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		}
	} for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		} int i=0; int i=0; i 0 i<max i max i++ i++ i {
			System.out.println(end[i]);
		} {
			System.out.println(end[i]);
		} System.out.println(end[i]) System.out.println System.out System System.out end[i] end i /*
	 * ポインタの位置
	 */
	public static int next(int a) {
		return (a + 1) % max;
	} next {
		return (a + 1) % max;
	} return (a + 1) % max; (a + 1) % max (a + 1) a 1 max int a a /*
	 * 入れる
	 */
	public static void enqueue(Object x) {
/*		if(next(rear) == front) {
			throw new IllegalStateException();
		}*/
		q[rear] = x;
		rear = next(rear);
	} enqueue {
/*		if(next(rear) == front) {
			throw new IllegalStateException();
		}*/
		q[rear] = x;
		rear = next(rear);
	} q[rear] = x q[rear] q rear x rear = next(rear) rear next(rear) next rear Object x x /*
	 * 取り出す
	 */
	public static Object dequeue() {
		Object x = q[front];
		q[front] = null;
		front = next(front);
		return x;
	} dequeue {
		Object x = q[front];
		q[front] = null;
		front = next(front);
		return x;
	} Object x = q[front]; x q[front] q front q[front] = null q[front] q front null front = next(front) front next(front) next front return x; x public class Main {

	private static int max; // 要素の数
	private static int run; // 処理速度
	private static Object q[]; // queue
	private static String end[]; // 処理済み
	private static int count; // 処理済み数
	private static int front; // 先頭
	private static int rear; // 末尾
	private static int time; // 合計処理時間

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

		max = sc.nextInt();
		run = sc.nextInt();

		q = new Object[max+1];
		front = rear = count = time = 0;
		end = new String[max];

		for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		}

		while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		}

		show();

		sc.close();
	}

	public static void show() {
		for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		}
	}

	/*
	 * ポインタの位置
	 */
	public static int next(int a) {
		return (a + 1) % max;
	}

	/*
	 * 入れる
	 */
	public static void enqueue(Object x) {
/*		if(next(rear) == front) {
			throw new IllegalStateException();
		}*/
		q[rear] = x;
		rear = next(rear);
	}

	/*
	 * 取り出す
	 */
	public static Object dequeue() {
		Object x = q[front];
		q[front] = null;
		front = next(front);
		return x;
	}
} public class Main {

	private static int max; // 要素の数
	private static int run; // 処理速度
	private static Object q[]; // queue
	private static String end[]; // 処理済み
	private static int count; // 処理済み数
	private static int front; // 先頭
	private static int rear; // 末尾
	private static int time; // 合計処理時間

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

		max = sc.nextInt();
		run = sc.nextInt();

		q = new Object[max+1];
		front = rear = count = time = 0;
		end = new String[max];

		for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		}

		while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		}

		show();

		sc.close();
	}

	public static void show() {
		for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		}
	}

	/*
	 * ポインタの位置
	 */
	public static int next(int a) {
		return (a + 1) % max;
	}

	/*
	 * 入れる
	 */
	public static void enqueue(Object x) {
/*		if(next(rear) == front) {
			throw new IllegalStateException();
		}*/
		q[rear] = x;
		rear = next(rear);
	}

	/*
	 * 取り出す
	 */
	public static Object dequeue() {
		Object x = q[front];
		q[front] = null;
		front = next(front);
		return x;
	}
} Main
import java.io.IOException;
import java.util.Scanner;
public class Main {

	private static int max; // 要素の数
	private static int run; // 処理速度
	private static Object q[]; // queue
	private static String end[]; // 処理済み
	private static int count; // 処理済み数
	private static int front; // 先頭
	private static int rear; // 末尾
	private static int time; // 合計処理時間

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

		max = sc.nextInt();
		run = sc.nextInt();

		q = new Object[max+1];
		front = rear = count = time = 0;
		end = new String[max];

		for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		}

		while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		}

		show();

		sc.close();
	}

	public static void show() {
		for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		}
	}

	/*
	 * ポインタの位置
	 */
	public static int next(int a) {
		return (a + 1) % max;
	}

	/*
	 * 入れる
	 */
	public static void enqueue(Object x) {
/*		if(next(rear) == front) {
			throw new IllegalStateException();
		}*/
		q[rear] = x;
		rear = next(rear);
	}

	/*
	 * 取り出す
	 */
	public static Object dequeue() {
		Object x = q[front];
		q[front] = null;
		front = next(front);
		return x;
	}
}
