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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		final int t = scan.nextInt();
		int totalTime = 0;

		Deque<String> queueName = new ArrayDeque<String>();
		Deque<Integer> queueTime = new ArrayDeque<Integer>();

		for(int i = 0; i < n; i++) {
			queueName.addLast(scan.next());
			queueTime.addLast(scan.nextInt());
		}

		while(!queueName.isEmpty()) {
			String procName = queueName.pollFirst();
			int procTime = queueTime.pollFirst();
			if(procTime <= t) {
				System.out.println(procName + " " + (procTime + totalTime));
				totalTime += procTime;
			} else {
				queueName.addLast(procName);
				queueTime.addLast(procTime - t);
				totalTime += t;
			}
		}
		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