
import java.util.AbstractMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

// the simulation of the round robin scheduler
public class Main {
	// log in the order of termination
	public static void simulate(Queue<Map.Entry<String, Integer>> budgets, int q) {
		int global_timer = 0;

		
		Map.Entry<String, Integer> budget;
		int time_consumpt;
		
		while(!budgets.isEmpty()) {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		}


		return;
		
	}
	
	
	
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int len = cin.nextInt();
		int q = cin.nextInt();


		Queue<Map.Entry<String, Integer>> budgets = new LinkedList<Map.Entry<String, Integer>>() ;
		
		for(int i = 0; i < len; i++) {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		}
		cin.close();
		
		simulate(budgets, q);
		

		
	}
} import java.util.AbstractMap; AbstractMap java.util import java.util.LinkedList; LinkedList java.util import java.util.Map; Map java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
	// log in the order of termination
	public static void simulate(Queue<Map.Entry<String, Integer>> budgets, int q) {
		int global_timer = 0;

		
		Map.Entry<String, Integer> budget;
		int time_consumpt;
		
		while(!budgets.isEmpty()) {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		}


		return;
		
	}
	
	
	
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int len = cin.nextInt();
		int q = cin.nextInt();


		Queue<Map.Entry<String, Integer>> budgets = new LinkedList<Map.Entry<String, Integer>>() ;
		
		for(int i = 0; i < len; i++) {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		}
		cin.close();
		
		simulate(budgets, q);
		

		
	}
} Main // log in the order of termination
	public static void simulate(Queue<Map.Entry<String, Integer>> budgets, int q) {
		int global_timer = 0;

		
		Map.Entry<String, Integer> budget;
		int time_consumpt;
		
		while(!budgets.isEmpty()) {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		}


		return;
		
	} simulate {
		int global_timer = 0;

		
		Map.Entry<String, Integer> budget;
		int time_consumpt;
		
		while(!budgets.isEmpty()) {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		}


		return;
		
	} int global_timer = 0; global_timer 0 Map.Entry<String, Integer> budget; budget int time_consumpt; time_consumpt while(!budgets.isEmpty()) {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		} !budgets.isEmpty() budgets.isEmpty() budgets.isEmpty budgets {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		} budget = budgets.poll() budget budgets.poll() budgets.poll budgets time_consumpt = Math.min(budget.getValue(), q) time_consumpt Math.min(budget.getValue(), q) Math.min Math budget.getValue() budget.getValue budget q budget.setValue(budget.getValue() - time_consumpt) budget.setValue budget budget.getValue() - time_consumpt budget.getValue() budget.getValue budget time_consumpt global_timer += time_consumpt global_timer time_consumpt if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				} budget.getValue() == 0 budget.getValue() budget.getValue budget 0 {
					System.out.println(budget.getKey() +" "+global_timer);
				} System.out.println(budget.getKey() +" "+global_timer) System.out.println System.out System System.out budget.getKey() +" "+global_timer budget.getKey() +" "+global_timer budget.getKey() budget.getKey budget " " global_timer {
					budgets.add(budget);
				} budgets.add(budget) budgets.add budgets budget return; Queue<Map.Entry<String, Integer>> budgets budgets int q q public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int len = cin.nextInt();
		int q = cin.nextInt();


		Queue<Map.Entry<String, Integer>> budgets = new LinkedList<Map.Entry<String, Integer>>() ;
		
		for(int i = 0; i < len; i++) {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		}
		cin.close();
		
		simulate(budgets, q);
		

		
	} main {
		Scanner cin = new Scanner(System.in);
		int len = cin.nextInt();
		int q = cin.nextInt();


		Queue<Map.Entry<String, Integer>> budgets = new LinkedList<Map.Entry<String, Integer>>() ;
		
		for(int i = 0; i < len; i++) {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		}
		cin.close();
		
		simulate(budgets, q);
		

		
	} Scanner cin = new Scanner(System.in); cin new Scanner(System.in) int len = cin.nextInt(); len cin.nextInt() cin.nextInt cin int q = cin.nextInt(); q cin.nextInt() cin.nextInt cin Queue<Map.Entry<String, Integer>> budgets = new LinkedList<Map.Entry<String, Integer>>() ; budgets new LinkedList<Map.Entry<String, Integer>>() for(int i = 0; i < len; i++) {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		} int i = 0; int i = 0; i 0 i < len i len i++ i++ i {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		} {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		} budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt())) budgets.add budgets new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()) cin.close() cin.close cin simulate(budgets, q) simulate budgets q String [] args args public class Main {
	// log in the order of termination
	public static void simulate(Queue<Map.Entry<String, Integer>> budgets, int q) {
		int global_timer = 0;

		
		Map.Entry<String, Integer> budget;
		int time_consumpt;
		
		while(!budgets.isEmpty()) {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		}


		return;
		
	}
	
	
	
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int len = cin.nextInt();
		int q = cin.nextInt();


		Queue<Map.Entry<String, Integer>> budgets = new LinkedList<Map.Entry<String, Integer>>() ;
		
		for(int i = 0; i < len; i++) {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		}
		cin.close();
		
		simulate(budgets, q);
		

		
	}
} public class Main {
	// log in the order of termination
	public static void simulate(Queue<Map.Entry<String, Integer>> budgets, int q) {
		int global_timer = 0;

		
		Map.Entry<String, Integer> budget;
		int time_consumpt;
		
		while(!budgets.isEmpty()) {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		}


		return;
		
	}
	
	
	
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int len = cin.nextInt();
		int q = cin.nextInt();


		Queue<Map.Entry<String, Integer>> budgets = new LinkedList<Map.Entry<String, Integer>>() ;
		
		for(int i = 0; i < len; i++) {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		}
		cin.close();
		
		simulate(budgets, q);
		

		
	}
} Main

import java.util.AbstractMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

// the simulation of the round robin scheduler
public class Main {
	// log in the order of termination
	public static void simulate(Queue<Map.Entry<String, Integer>> budgets, int q) {
		int global_timer = 0;

		
		Map.Entry<String, Integer> budget;
		int time_consumpt;
		
		while(!budgets.isEmpty()) {
				budget = budgets.poll();
				time_consumpt = Math.min(budget.getValue(), q);
				budget.setValue(budget.getValue() - time_consumpt);
				global_timer += time_consumpt;
				if(budget.getValue() == 0) {
					System.out.println(budget.getKey() +" "+global_timer);
				}else {
					budgets.add(budget);
				}
		}


		return;
		
	}
	
	
	
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int len = cin.nextInt();
		int q = cin.nextInt();


		Queue<Map.Entry<String, Integer>> budgets = new LinkedList<Map.Entry<String, Integer>>() ;
		
		for(int i = 0; i < len; i++) {
			budgets.add(new AbstractMap.SimpleEntry<String, Integer>(cin.next(), cin.nextInt()));
		}
		cin.close();
		
		simulate(budgets, q);
		

		
	}
}