import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Queue<String> nameQueue = new ArrayDeque<>();
		Queue<Integer> timeQueue = new ArrayDeque<>();
		int time = 0;

		// プロセス数とクオンタムを読み込む
		int num = scan.nextInt();
		int quantum = scan.nextInt();

		// 各プロセスの情報を読み込む
		for(int i = 0; i < num; i++) {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		}

		// ラウンドロビンスケジューリング
		while(!timeQueue.isEmpty()) {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		}

	}
}
 import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Queue<String> nameQueue = new ArrayDeque<>();
		Queue<Integer> timeQueue = new ArrayDeque<>();
		int time = 0;

		// プロセス数とクオンタムを読み込む
		int num = scan.nextInt();
		int quantum = scan.nextInt();

		// 各プロセスの情報を読み込む
		for(int i = 0; i < num; i++) {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		}

		// ラウンドロビンスケジューリング
		while(!timeQueue.isEmpty()) {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		}

	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Queue<String> nameQueue = new ArrayDeque<>();
		Queue<Integer> timeQueue = new ArrayDeque<>();
		int time = 0;

		// プロセス数とクオンタムを読み込む
		int num = scan.nextInt();
		int quantum = scan.nextInt();

		// 各プロセスの情報を読み込む
		for(int i = 0; i < num; i++) {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		}

		// ラウンドロビンスケジューリング
		while(!timeQueue.isEmpty()) {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		}

	} main {
		Scanner scan = new Scanner(System.in);
		Queue<String> nameQueue = new ArrayDeque<>();
		Queue<Integer> timeQueue = new ArrayDeque<>();
		int time = 0;

		// プロセス数とクオンタムを読み込む
		int num = scan.nextInt();
		int quantum = scan.nextInt();

		// 各プロセスの情報を読み込む
		for(int i = 0; i < num; i++) {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		}

		// ラウンドロビンスケジューリング
		while(!timeQueue.isEmpty()) {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) Queue<String> nameQueue = new ArrayDeque<>(); nameQueue new ArrayDeque<>() Queue<Integer> timeQueue = new ArrayDeque<>(); timeQueue new ArrayDeque<>() int time = 0; time 0 int num = scan.nextInt(); num scan.nextInt() scan.nextInt scan int quantum = scan.nextInt(); quantum scan.nextInt() scan.nextInt scan for(int i = 0; i < num; i++) {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		} {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		} nameQueue.add(scan.next()) nameQueue.add nameQueue scan.next() scan.next scan timeQueue.add(scan.nextInt()) timeQueue.add timeQueue scan.nextInt() scan.nextInt scan while(!timeQueue.isEmpty()) {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		} !timeQueue.isEmpty() timeQueue.isEmpty() timeQueue.isEmpty timeQueue {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		} if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			} timeQueue.peek() > quantum timeQueue.peek() timeQueue.peek timeQueue quantum {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} timeQueue.add(timeQueue.poll() - quantum) timeQueue.add timeQueue timeQueue.poll() - quantum timeQueue.poll() timeQueue.poll timeQueue quantum nameQueue.add(nameQueue.poll()) nameQueue.add nameQueue nameQueue.poll() nameQueue.poll nameQueue time += quantum time quantum {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			} time += timeQueue.poll() time timeQueue.poll() timeQueue.poll timeQueue System.out.print(nameQueue.poll() + " ") System.out.print System.out System System.out nameQueue.poll() + " " nameQueue.poll() nameQueue.poll nameQueue " " System.out.println(time) System.out.println System.out System System.out time String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Queue<String> nameQueue = new ArrayDeque<>();
		Queue<Integer> timeQueue = new ArrayDeque<>();
		int time = 0;

		// プロセス数とクオンタムを読み込む
		int num = scan.nextInt();
		int quantum = scan.nextInt();

		// 各プロセスの情報を読み込む
		for(int i = 0; i < num; i++) {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		}

		// ラウンドロビンスケジューリング
		while(!timeQueue.isEmpty()) {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		}

	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Queue<String> nameQueue = new ArrayDeque<>();
		Queue<Integer> timeQueue = new ArrayDeque<>();
		int time = 0;

		// プロセス数とクオンタムを読み込む
		int num = scan.nextInt();
		int quantum = scan.nextInt();

		// 各プロセスの情報を読み込む
		for(int i = 0; i < num; i++) {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		}

		// ラウンドロビンスケジューリング
		while(!timeQueue.isEmpty()) {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		}

	}
} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Queue<String> nameQueue = new ArrayDeque<>();
		Queue<Integer> timeQueue = new ArrayDeque<>();
		int time = 0;

		// プロセス数とクオンタムを読み込む
		int num = scan.nextInt();
		int quantum = scan.nextInt();

		// 各プロセスの情報を読み込む
		for(int i = 0; i < num; i++) {
			nameQueue.add(scan.next());
			timeQueue.add(scan.nextInt());
		}

		// ラウンドロビンスケジューリング
		while(!timeQueue.isEmpty()) {
			if(timeQueue.peek() > quantum) {
				timeQueue.add(timeQueue.poll() - quantum);
				nameQueue.add(nameQueue.poll());
				time += quantum;
			} else {
				time += timeQueue.poll();
				System.out.print(nameQueue.poll() + " ");
				System.out.println(time);
			}

		}

	}
}

