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

public class Main {
	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		Queue<DataS> queue = new ArrayDeque<>();
		int n = scan.nextInt();
		int q = scan.nextInt();
		for (int i = 0; i < n ; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			DataS dataS = new DataS( name, time );
			queue.add(dataS);
		}

		int time = 0;
		while(queue.size() != 0) {
			DataS dataS = queue.poll();
			int dataTime = dataS.getTime();
			if(dataTime > q) {
				time += q;
				dataS.setTime(dataTime - q);
				queue.add(dataS);
			}else {
				time += dataS.getTime();
				System.out.println(dataS.getName() + " " + time);
			}
		}

	}

	static class DataS{
		private String name;
		private int time;
		public DataS(String name , int time) {
			this.name = name;
			this.time = time;
		}
		public String getName() {
			return name;
		}

		public void setTime(int time) {
			this.time = time;
		}

		public int getTime() {
			return time;
		}
	}

}


/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