import java.util.Scanner;

/**
 * キュー
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=ja">ALDS1_3_B</a>
 */
public class Main {

	private static final int LEN = 100005;
	private static int head, tail;
	private static P Q[] = new P[LEN];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		for (int i = 0; i < LEN; i++) {
			Q[i] = new P();
		}

		for (int i = 1; i <= n; i++) {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		}

		head = 1;
		tail = n + 1;

		P u;
		int elapse = 0;
		while (head != tail) {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		}

		sc.close();
	}

	private static void enqueue(P x) {
		Q[tail] = x;
		tail = (tail + 1) % LEN;
	}

	private static P dequeue() {
		P x = Q[head];
		head = (head + 1) % LEN;
		return x;
	}

}

class P {
	String name;;
	int t;
} import java.util.Scanner; Scanner java.util public class Main {

	private static final int LEN = 100005;
	private static int head, tail;
	private static P Q[] = new P[LEN];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		for (int i = 0; i < LEN; i++) {
			Q[i] = new P();
		}

		for (int i = 1; i <= n; i++) {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		}

		head = 1;
		tail = n + 1;

		P u;
		int elapse = 0;
		while (head != tail) {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		}

		sc.close();
	}

	private static void enqueue(P x) {
		Q[tail] = x;
		tail = (tail + 1) % LEN;
	}

	private static P dequeue() {
		P x = Q[head];
		head = (head + 1) % LEN;
		return x;
	}

} Main private static final int LEN = 100005; LEN 100005 private static int head head tail; tail private static P Q[] = new P[LEN]; Q new P[LEN] LEN public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		for (int i = 0; i < LEN; i++) {
			Q[i] = new P();
		}

		for (int i = 1; i <= n; i++) {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		}

		head = 1;
		tail = n + 1;

		P u;
		int elapse = 0;
		while (head != tail) {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		}

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		for (int i = 0; i < LEN; i++) {
			Q[i] = new P();
		}

		for (int i = 1; i <= n; i++) {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		}

		head = 1;
		tail = n + 1;

		P u;
		int elapse = 0;
		while (head != tail) {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		}

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc for (int i = 0; i < LEN; i++) {
			Q[i] = new P();
		} int i = 0; int i = 0; i 0 i < LEN i LEN i++ i++ i {
			Q[i] = new P();
		} {
			Q[i] = new P();
		} Q[i] = new P() Q[i] Q i new P() for (int i = 1; i <= n; i++) {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		} {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		} Q[i].name = sc.next() Q[i].name Q[i] Q i Q[i].name sc.next() sc.next sc Q[i].t = sc.nextInt() Q[i].t Q[i] Q i Q[i].t sc.nextInt() sc.nextInt sc head = 1 head 1 tail = n + 1 tail n + 1 n 1 P u; u int elapse = 0; elapse 0 while (head != tail) {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		} head != tail head tail {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		} u = dequeue() u dequeue() dequeue int c = Math.min(q, u.t); c Math.min(q, u.t) Math.min Math q u.t u u.t u.t -= c u.t u u.t c elapse += c elapse c if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			} 0 < u.t 0 u.t u u.t {
				enqueue(u);
			} enqueue(u) enqueue u {
				System.out.println(u.name + " " + elapse);
			} System.out.println(u.name + " " + elapse) System.out.println System.out System System.out u.name + " " + elapse u.name + " " + elapse u.name u u.name " " elapse sc.close() sc.close sc String[] args args private static void enqueue(P x) {
		Q[tail] = x;
		tail = (tail + 1) % LEN;
	} enqueue {
		Q[tail] = x;
		tail = (tail + 1) % LEN;
	} Q[tail] = x Q[tail] Q tail x tail = (tail + 1) % LEN tail (tail + 1) % LEN (tail + 1) tail 1 LEN P x x private static P dequeue() {
		P x = Q[head];
		head = (head + 1) % LEN;
		return x;
	} dequeue {
		P x = Q[head];
		head = (head + 1) % LEN;
		return x;
	} P x = Q[head]; x Q[head] Q head head = (head + 1) % LEN head (head + 1) % LEN (head + 1) head 1 LEN return x; x class P {
	String name;;
	int t;
} P String name; name int t; t public class Main {

	private static final int LEN = 100005;
	private static int head, tail;
	private static P Q[] = new P[LEN];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		for (int i = 0; i < LEN; i++) {
			Q[i] = new P();
		}

		for (int i = 1; i <= n; i++) {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		}

		head = 1;
		tail = n + 1;

		P u;
		int elapse = 0;
		while (head != tail) {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		}

		sc.close();
	}

	private static void enqueue(P x) {
		Q[tail] = x;
		tail = (tail + 1) % LEN;
	}

	private static P dequeue() {
		P x = Q[head];
		head = (head + 1) % LEN;
		return x;
	}

} public class Main {

	private static final int LEN = 100005;
	private static int head, tail;
	private static P Q[] = new P[LEN];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		for (int i = 0; i < LEN; i++) {
			Q[i] = new P();
		}

		for (int i = 1; i <= n; i++) {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		}

		head = 1;
		tail = n + 1;

		P u;
		int elapse = 0;
		while (head != tail) {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		}

		sc.close();
	}

	private static void enqueue(P x) {
		Q[tail] = x;
		tail = (tail + 1) % LEN;
	}

	private static P dequeue() {
		P x = Q[head];
		head = (head + 1) % LEN;
		return x;
	}

} Main
import java.util.Scanner;

/**
 * キュー
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=ja">ALDS1_3_B</a>
 */
public class Main {

	private static final int LEN = 100005;
	private static int head, tail;
	private static P Q[] = new P[LEN];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		for (int i = 0; i < LEN; i++) {
			Q[i] = new P();
		}

		for (int i = 1; i <= n; i++) {
			Q[i].name = sc.next();
			Q[i].t = sc.nextInt();
		}

		head = 1;
		tail = n + 1;

		P u;
		int elapse = 0;
		while (head != tail) {
			u = dequeue();
			int c = Math.min(q, u.t);
			u.t -= c;
			elapse += c;
			if (0 < u.t) {
				enqueue(u);
			} else {
				System.out.println(u.name + " " + elapse);
			}
		}

		sc.close();
	}

	private static void enqueue(P x) {
		Q[tail] = x;
		tail = (tail + 1) % LEN;
	}

	private static P dequeue() {
		P x = Q[head];
		head = (head + 1) % LEN;
		return x;
	}

}

class P {
	String name;;
	int t;
}
