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);
		int num, quantum = 0;
		int time = 0; // time;総時間数
		Queue<String> qName = new ArrayDeque<String>();
		Queue<Integer> qTime = new ArrayDeque<Integer>();

		num = scan.nextInt(); // 入力数
		quantum = scan.nextInt(); // クオンタム（実行する処理時間）
		scan.nextLine();

		for (int i = 0; i < num; i++) {
			qName.add(scan.next());
			qTime.add(scan.nextInt());
		}

		while (!qName.isEmpty()) {
			String qNamePolled = qName.poll();
			int getTime = qTime.poll();

			if (getTime > quantum) { // 総時間数をカウントしていく
				time = time + quantum;
			} else {
				time = time + getTime;
			}

			if (getTime > quantum) {
				qTime.add(getTime - quantum);
				qName.add(qNamePolled);
			} else { // 今のプロセス処理終了
				System.out.println(qNamePolled + " " + time);
			}
		}
		scan.close();
	}
}


/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz