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

public class Main {
	
	public static void main(String[] args) {
		
		int numberOfProcesses;
		int quantum;
		int clock = 0;
		String line;
		
		Queue<String> taskQueue = new LinkedList<String>();
		Queue<Integer> timeQueue = new LinkedList<Integer>();
		
		Scanner keyboard = new Scanner(System.in);
		Scanner input;
		
		line = keyboard.nextLine();
		
		input = new Scanner(line);
		
		numberOfProcesses = Integer.parseInt(input.next());
		quantum = Integer.parseInt(input.next());
		
		for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		}
		
		while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		}
		
		
		
	}

} 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) {
		
		int numberOfProcesses;
		int quantum;
		int clock = 0;
		String line;
		
		Queue<String> taskQueue = new LinkedList<String>();
		Queue<Integer> timeQueue = new LinkedList<Integer>();
		
		Scanner keyboard = new Scanner(System.in);
		Scanner input;
		
		line = keyboard.nextLine();
		
		input = new Scanner(line);
		
		numberOfProcesses = Integer.parseInt(input.next());
		quantum = Integer.parseInt(input.next());
		
		for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		}
		
		while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		}
		
		
		
	}

} Main public static void main(String[] args) {
		
		int numberOfProcesses;
		int quantum;
		int clock = 0;
		String line;
		
		Queue<String> taskQueue = new LinkedList<String>();
		Queue<Integer> timeQueue = new LinkedList<Integer>();
		
		Scanner keyboard = new Scanner(System.in);
		Scanner input;
		
		line = keyboard.nextLine();
		
		input = new Scanner(line);
		
		numberOfProcesses = Integer.parseInt(input.next());
		quantum = Integer.parseInt(input.next());
		
		for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		}
		
		while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		}
		
		
		
	} main {
		
		int numberOfProcesses;
		int quantum;
		int clock = 0;
		String line;
		
		Queue<String> taskQueue = new LinkedList<String>();
		Queue<Integer> timeQueue = new LinkedList<Integer>();
		
		Scanner keyboard = new Scanner(System.in);
		Scanner input;
		
		line = keyboard.nextLine();
		
		input = new Scanner(line);
		
		numberOfProcesses = Integer.parseInt(input.next());
		quantum = Integer.parseInt(input.next());
		
		for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		}
		
		while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		}
		
		
		
	} int numberOfProcesses; numberOfProcesses int quantum; quantum int clock = 0; clock 0 String line; line Queue<String> taskQueue = new LinkedList<String>(); taskQueue new LinkedList<String>() Queue<Integer> timeQueue = new LinkedList<Integer>(); timeQueue new LinkedList<Integer>() Scanner keyboard = new Scanner(System.in); keyboard new Scanner(System.in) Scanner input; input line = keyboard.nextLine() line keyboard.nextLine() keyboard.nextLine keyboard input = new Scanner(line) input new Scanner(line) numberOfProcesses = Integer.parseInt(input.next()) numberOfProcesses Integer.parseInt(input.next()) Integer.parseInt Integer input.next() input.next input quantum = Integer.parseInt(input.next()) quantum Integer.parseInt(input.next()) Integer.parseInt Integer input.next() input.next input for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		} int i = 0; int i = 0; i 0 i < numberOfProcesses i numberOfProcesses i++ i++ i {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		} {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		} line = keyboard.nextLine() line keyboard.nextLine() keyboard.nextLine keyboard input = new Scanner(line) input new Scanner(line) taskQueue.add(input.next()) taskQueue.add taskQueue input.next() input.next input timeQueue.add(Integer.parseInt(input.next())) timeQueue.add timeQueue Integer.parseInt(input.next()) Integer.parseInt Integer input.next() input.next input while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		} !taskQueue.isEmpty() taskQueue.isEmpty() taskQueue.isEmpty taskQueue {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		} String currentTask = taskQueue.remove(); currentTask taskQueue.remove() taskQueue.remove taskQueue int currentTime = timeQueue.remove(); currentTime timeQueue.remove() timeQueue.remove timeQueue if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			} currentTime > quantum currentTime quantum {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			} currentTime = currentTime - quantum currentTime currentTime - quantum currentTime quantum taskQueue.add(currentTask) taskQueue.add taskQueue currentTask timeQueue.add(currentTime) timeQueue.add timeQueue currentTime clock = clock + quantum clock clock + quantum clock quantum {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			} clock = clock + currentTime clock clock + currentTime clock currentTime System.out.print(currentTask + " ") System.out.print System.out System System.out currentTask + " " currentTask " " System.out.println(clock) System.out.println System.out System System.out clock String[] args args public class Main {
	
	public static void main(String[] args) {
		
		int numberOfProcesses;
		int quantum;
		int clock = 0;
		String line;
		
		Queue<String> taskQueue = new LinkedList<String>();
		Queue<Integer> timeQueue = new LinkedList<Integer>();
		
		Scanner keyboard = new Scanner(System.in);
		Scanner input;
		
		line = keyboard.nextLine();
		
		input = new Scanner(line);
		
		numberOfProcesses = Integer.parseInt(input.next());
		quantum = Integer.parseInt(input.next());
		
		for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		}
		
		while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		}
		
		
		
	}

} public class Main {
	
	public static void main(String[] args) {
		
		int numberOfProcesses;
		int quantum;
		int clock = 0;
		String line;
		
		Queue<String> taskQueue = new LinkedList<String>();
		Queue<Integer> timeQueue = new LinkedList<Integer>();
		
		Scanner keyboard = new Scanner(System.in);
		Scanner input;
		
		line = keyboard.nextLine();
		
		input = new Scanner(line);
		
		numberOfProcesses = Integer.parseInt(input.next());
		quantum = Integer.parseInt(input.next());
		
		for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		}
		
		while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		}
		
		
		
	}

} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		int numberOfProcesses;
		int quantum;
		int clock = 0;
		String line;
		
		Queue<String> taskQueue = new LinkedList<String>();
		Queue<Integer> timeQueue = new LinkedList<Integer>();
		
		Scanner keyboard = new Scanner(System.in);
		Scanner input;
		
		line = keyboard.nextLine();
		
		input = new Scanner(line);
		
		numberOfProcesses = Integer.parseInt(input.next());
		quantum = Integer.parseInt(input.next());
		
		for(int i = 0; i < numberOfProcesses; i++) {
			line = keyboard.nextLine();
			input = new Scanner(line);
			
			taskQueue.add(input.next());
			timeQueue.add(Integer.parseInt(input.next()));
		}
		
		while(!taskQueue.isEmpty()) {
			
			String currentTask = taskQueue.remove();
			int currentTime = timeQueue.remove();
			
			if(currentTime > quantum) {
				currentTime = currentTime - quantum;
				
				taskQueue.add(currentTask);
				timeQueue.add(currentTime);
				
				clock = clock + quantum;
			}
			else {
				
				clock = clock + currentTime;
				
				System.out.print(currentTask + " ");
				System.out.println(clock);
			}
		}
		
		
		
	}

}
