import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		Deque<String> nameQueue = new ArrayDeque<String>();
		Deque<Integer> timeQueue = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		}
		int nowTime = 0;

		while (!nameQueue.isEmpty() && !timeQueue.isEmpty()) {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		}

		sc.close();
	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		Deque<String> nameQueue = new ArrayDeque<String>();
		Deque<Integer> timeQueue = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		}
		int nowTime = 0;

		while (!nameQueue.isEmpty() && !timeQueue.isEmpty()) {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		}

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

		Deque<String> nameQueue = new ArrayDeque<String>();
		Deque<Integer> timeQueue = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		}
		int nowTime = 0;

		while (!nameQueue.isEmpty() && !timeQueue.isEmpty()) {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		}

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

		Deque<String> nameQueue = new ArrayDeque<String>();
		Deque<Integer> timeQueue = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		}
		int nowTime = 0;

		while (!nameQueue.isEmpty() && !timeQueue.isEmpty()) {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		}

		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 Deque<String> nameQueue = new ArrayDeque<String>(); nameQueue new ArrayDeque<String>() Deque<Integer> timeQueue = new ArrayDeque<Integer>(); timeQueue new ArrayDeque<Integer>() for (int i = 0; i < n; i++) {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		} {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		} nameQueue.offer(sc.next()) nameQueue.offer nameQueue sc.next() sc.next sc timeQueue.offer(sc.nextInt()) timeQueue.offer timeQueue sc.nextInt() sc.nextInt sc int nowTime = 0; nowTime 0 while (!nameQueue.isEmpty() && !timeQueue.isEmpty()) {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		} !nameQueue.isEmpty() && !timeQueue.isEmpty() !nameQueue.isEmpty() nameQueue.isEmpty() nameQueue.isEmpty nameQueue !timeQueue.isEmpty() timeQueue.isEmpty() timeQueue.isEmpty timeQueue {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		} String p = nameQueue.poll(); p nameQueue.poll() nameQueue.poll nameQueue int t = timeQueue.poll(); t timeQueue.poll() timeQueue.poll timeQueue if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			} t - q <= 0 t - q t q 0 {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} nowTime += t nowTime t System.out.println(p + " " + String.valueOf(nowTime)) System.out.println System.out System System.out p + " " + String.valueOf(nowTime) p + " " + String.valueOf(nowTime) p " " String.valueOf(nowTime) String.valueOf String nowTime {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			} nameQueue.offer(p) nameQueue.offer nameQueue p timeQueue.offer(t - q) timeQueue.offer timeQueue t - q t q nowTime += q nowTime q sc.close() sc.close sc public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		Deque<String> nameQueue = new ArrayDeque<String>();
		Deque<Integer> timeQueue = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		}
		int nowTime = 0;

		while (!nameQueue.isEmpty() && !timeQueue.isEmpty()) {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		}

		sc.close();
	}
} public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		Deque<String> nameQueue = new ArrayDeque<String>();
		Deque<Integer> timeQueue = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		}
		int nowTime = 0;

		while (!nameQueue.isEmpty() && !timeQueue.isEmpty()) {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		}

		sc.close();
	}
} Main
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		Deque<String> nameQueue = new ArrayDeque<String>();
		Deque<Integer> timeQueue = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			nameQueue.offer(sc.next());
			timeQueue.offer(sc.nextInt());
		}
		int nowTime = 0;

		while (!nameQueue.isEmpty() && !timeQueue.isEmpty()) {
			String p = nameQueue.poll();
			int t = timeQueue.poll();
			if (t - q <= 0) {
				nowTime += t;
				System.out.println(p + " " + String.valueOf(nowTime));
			} else {
				nameQueue.offer(p);
				timeQueue.offer(t - q);
				nowTime += q;
			}
		}

		sc.close();
	}
}