import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] nAndQuantum = new String[2];
		nAndQuantum = input.nextLine().split(" ");
		int n = Integer.parseInt(nAndQuantum[0]);
		int quantum = Integer.parseInt(nAndQuantum[1]);
		Queue<Integer> times = new LinkedList<Integer>();
		Queue<String> names = new LinkedList<String>();
		String[] nameAndTime = new String[2];
		for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		}
		int totalTime = 0;
		while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		}

	}

} import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] nAndQuantum = new String[2];
		nAndQuantum = input.nextLine().split(" ");
		int n = Integer.parseInt(nAndQuantum[0]);
		int quantum = Integer.parseInt(nAndQuantum[1]);
		Queue<Integer> times = new LinkedList<Integer>();
		Queue<String> names = new LinkedList<String>();
		String[] nameAndTime = new String[2];
		for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		}
		int totalTime = 0;
		while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		}

	}

} Main public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] nAndQuantum = new String[2];
		nAndQuantum = input.nextLine().split(" ");
		int n = Integer.parseInt(nAndQuantum[0]);
		int quantum = Integer.parseInt(nAndQuantum[1]);
		Queue<Integer> times = new LinkedList<Integer>();
		Queue<String> names = new LinkedList<String>();
		String[] nameAndTime = new String[2];
		for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		}
		int totalTime = 0;
		while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		}

	} main {
		Scanner input = new Scanner(System.in);
		String[] nAndQuantum = new String[2];
		nAndQuantum = input.nextLine().split(" ");
		int n = Integer.parseInt(nAndQuantum[0]);
		int quantum = Integer.parseInt(nAndQuantum[1]);
		Queue<Integer> times = new LinkedList<Integer>();
		Queue<String> names = new LinkedList<String>();
		String[] nameAndTime = new String[2];
		for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		}
		int totalTime = 0;
		while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		}

	} Scanner input = new Scanner(System.in); input new Scanner(System.in) String[] nAndQuantum = new String[2]; nAndQuantum new String[2] 2 nAndQuantum = input.nextLine().split(" ") nAndQuantum input.nextLine().split(" ") input.nextLine().split input.nextLine() input.nextLine input " " int n = Integer.parseInt(nAndQuantum[0]); n Integer.parseInt(nAndQuantum[0]) Integer.parseInt Integer nAndQuantum[0] nAndQuantum 0 int quantum = Integer.parseInt(nAndQuantum[1]); quantum Integer.parseInt(nAndQuantum[1]) Integer.parseInt Integer nAndQuantum[1] nAndQuantum 1 Queue<Integer> times = new LinkedList<Integer>(); times new LinkedList<Integer>() Queue<String> names = new LinkedList<String>(); names new LinkedList<String>() String[] nameAndTime = new String[2]; nameAndTime new String[2] 2 for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		} {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		} nameAndTime = input.nextLine().split(" ") nameAndTime input.nextLine().split(" ") input.nextLine().split input.nextLine() input.nextLine input " " names.add(nameAndTime[0]) names.add names nameAndTime[0] nameAndTime 0 times.add(Integer.parseInt(nameAndTime[1])) times.add times Integer.parseInt(nameAndTime[1]) Integer.parseInt Integer nameAndTime[1] nameAndTime 1 int totalTime = 0; totalTime 0 while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		} !times.isEmpty() && !names.isEmpty() !times.isEmpty() times.isEmpty() times.isEmpty times !names.isEmpty() names.isEmpty() names.isEmpty names {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		} String name; name int time; time if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			} times.peek() > quantum times.peek() times.peek times quantum {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			} time = times.poll() time times.poll() times.poll times totalTime = totalTime + quantum totalTime totalTime + quantum totalTime quantum name = names.poll() name names.poll() names.poll names time = time - quantum time time - quantum time quantum times.add(time) times.add times time names.add(name) names.add names name if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			} times.peek() <= quantum times.peek() times.peek times quantum {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			} time = times.poll() time times.poll() times.poll times totalTime = totalTime + time totalTime totalTime + time totalTime time name = names.poll() name names.poll() names.poll names System.out.println(name + " " + totalTime) System.out.println System.out System System.out name + " " + totalTime name + " " + totalTime name " " totalTime String[] args args public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] nAndQuantum = new String[2];
		nAndQuantum = input.nextLine().split(" ");
		int n = Integer.parseInt(nAndQuantum[0]);
		int quantum = Integer.parseInt(nAndQuantum[1]);
		Queue<Integer> times = new LinkedList<Integer>();
		Queue<String> names = new LinkedList<String>();
		String[] nameAndTime = new String[2];
		for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		}
		int totalTime = 0;
		while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		}

	}

} public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] nAndQuantum = new String[2];
		nAndQuantum = input.nextLine().split(" ");
		int n = Integer.parseInt(nAndQuantum[0]);
		int quantum = Integer.parseInt(nAndQuantum[1]);
		Queue<Integer> times = new LinkedList<Integer>();
		Queue<String> names = new LinkedList<String>();
		String[] nameAndTime = new String[2];
		for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		}
		int totalTime = 0;
		while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		}

	}

} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] nAndQuantum = new String[2];
		nAndQuantum = input.nextLine().split(" ");
		int n = Integer.parseInt(nAndQuantum[0]);
		int quantum = Integer.parseInt(nAndQuantum[1]);
		Queue<Integer> times = new LinkedList<Integer>();
		Queue<String> names = new LinkedList<String>();
		String[] nameAndTime = new String[2];
		for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		}
		int totalTime = 0;
		while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		}

	}

}
