import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		String output = "";
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		}
		System.out.print(output);

	}
	
	private static Integer get_time(String process, Integer quantum){
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	}

} import java.util.*; util.* java public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		String output = "";
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		}
		System.out.print(output);

	}
	
	private static Integer get_time(String process, Integer quantum){
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	}

} Main /**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		String output = "";
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		}
		System.out.print(output);

	} main {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		String output = "";
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		}
		System.out.print(output);

	} Scanner s = new Scanner(System.in); s new Scanner(System.in) String input = s.nextLine(); input s.nextLine() s.nextLine s Integer number = Integer.parseInt(input.split(" ")[0]); number Integer.parseInt(input.split(" ")[0]) Integer.parseInt Integer input.split(" ")[0] input.split(" ") input.split input " " 0 Integer quantum = Integer.parseInt(input.split(" ")[1]); quantum Integer.parseInt(input.split(" ")[1]) Integer.parseInt Integer input.split(" ")[1] input.split(" ") input.split input " " 1 Integer current_time = 0; current_time 0 ArrayList<String> queue = new ArrayList<String>(); queue new ArrayList<String>() while(s.hasNext()){
			queue.add(s.nextLine());
		} s.hasNext() s.hasNext s {
			queue.add(s.nextLine());
		} queue.add(s.nextLine()) queue.add queue s.nextLine() s.nextLine s s.close() s.close s String output = ""; output "" while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		} queue.size() > 0 queue.size() queue.size queue 0 {
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		} String process = queue.remove(0); process queue.remove(0) queue.remove queue 0 Integer result = get_time(process, quantum); result get_time(process, quantum) get_time process quantum if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			} result <= 0 result 0 {
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			} current_time = current_time + quantum + result current_time current_time + quantum + result current_time + quantum + result current_time quantum result output = output + process.split(" ")[0] + " " + current_time + "\n" output output + process.split(" ")[0] + " " + current_time + "\n" current_time " " output + process.split(" ")[0] + " " + current_time + "\n" output process.split(" ")[0] process.split(" ") process.split process " " 0 " " current_time "\n" {
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			} current_time += quantum current_time quantum String process_result = process.split(" ")[0] + " " + result.toString(); process_result process.split(" ")[0] + " " + result.toString() process.split(" ")[0] + " " + result.toString() process.split(" ")[0] process.split(" ") process.split process " " 0 " " result.toString() result.toString result queue.add(process_result) queue.add queue process_result if(output.length() > 1000){
				System.out.print(output);
				output = "";
			} output.length() > 1000 output.length() output.length output 1000 {
				System.out.print(output);
				output = "";
			} System.out.print(output) System.out.print System.out System System.out output output = "" output "" System.out.print(output) System.out.print System.out System System.out output String[] args args private static Integer get_time(String process, Integer quantum){
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	} get_time {
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	} Integer time = Integer.parseInt(process.split(" ")[1]); time Integer.parseInt(process.split(" ")[1]) Integer.parseInt Integer process.split(" ")[1] process.split(" ") process.split process " " 1 return time - quantum; time - quantum time quantum String process process Integer quantum quantum public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		String output = "";
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		}
		System.out.print(output);

	}
	
	private static Integer get_time(String process, Integer quantum){
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	}

} public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		String output = "";
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		}
		System.out.print(output);

	}
	
	private static Integer get_time(String process, Integer quantum){
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	}

} Main
import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		String output = "";
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		}
		System.out.print(output);

	}
	
	private static Integer get_time(String process, Integer quantum){
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	}

}