import java.util.*;

public class Main{	

public static void main(String[] args) {
	Queue<String> name = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	Scanner in = new Scanner(System.in);
	
	int elems = in.nextInt();
	int timer = in.nextInt();
	int timePassed = 0;
	in.nextLine();
	
	String eName = "";
	int eTime = 0;
	
	for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	}
	
	while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	}
}
}

/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