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

public class Main{
	String name;
	int time;
	static int totalTime = 0;


	

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String line = in.nextLine(); 
		String[] words = line.split(" ");
		Problem currentItem;
		Queue<Problem> myQueue = new LinkedList<Problem>();
		int pro = Integer.parseInt(words[0]);
		int Required = Integer.parseInt(words[1]);

		for(int i = 0; i < pro; i++) {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		}
		in.close();


		//System.out.println("StartQueue");
		while(!myQueue.isEmpty()) {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		}


	}
}
	class Problem {
	String name;
	int time;
	public Problem(String name, int time){
		this.name = name;
		this.time = time;
	}
	} import java.util.Scanner; Scanner java.util import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util public class Main{
	String name;
	int time;
	static int totalTime = 0;


	

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String line = in.nextLine(); 
		String[] words = line.split(" ");
		Problem currentItem;
		Queue<Problem> myQueue = new LinkedList<Problem>();
		int pro = Integer.parseInt(words[0]);
		int Required = Integer.parseInt(words[1]);

		for(int i = 0; i < pro; i++) {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		}
		in.close();


		//System.out.println("StartQueue");
		while(!myQueue.isEmpty()) {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		}


	}
} Main String name; name int time; time static int totalTime = 0; totalTime 0 public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String line = in.nextLine(); 
		String[] words = line.split(" ");
		Problem currentItem;
		Queue<Problem> myQueue = new LinkedList<Problem>();
		int pro = Integer.parseInt(words[0]);
		int Required = Integer.parseInt(words[1]);

		for(int i = 0; i < pro; i++) {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		}
		in.close();


		//System.out.println("StartQueue");
		while(!myQueue.isEmpty()) {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		}


	} main {

		Scanner in = new Scanner(System.in);
		String line = in.nextLine(); 
		String[] words = line.split(" ");
		Problem currentItem;
		Queue<Problem> myQueue = new LinkedList<Problem>();
		int pro = Integer.parseInt(words[0]);
		int Required = Integer.parseInt(words[1]);

		for(int i = 0; i < pro; i++) {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		}
		in.close();


		//System.out.println("StartQueue");
		while(!myQueue.isEmpty()) {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		}


	} Scanner in = new Scanner(System.in); in new Scanner(System.in) String line = in.nextLine(); line in.nextLine() in.nextLine in String[] words = line.split(" "); words line.split(" ") line.split line " " Problem currentItem; currentItem Queue<Problem> myQueue = new LinkedList<Problem>(); myQueue new LinkedList<Problem>() int pro = Integer.parseInt(words[0]); pro Integer.parseInt(words[0]) Integer.parseInt Integer words[0] words 0 int Required = Integer.parseInt(words[1]); Required Integer.parseInt(words[1]) Integer.parseInt Integer words[1] words 1 for(int i = 0; i < pro; i++) {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		} int i = 0; int i = 0; i 0 i < pro i pro i++ i++ i {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		} {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		} line = in.nextLine() line in.nextLine() in.nextLine in words = line.split(" ") words line.split(" ") line.split line " " myQueue.offer(new Problem(words[0], Integer.parseInt(words[1]))) myQueue.offer myQueue new Problem(words[0], Integer.parseInt(words[1])) in.close() in.close in while(!myQueue.isEmpty()) {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		} !myQueue.isEmpty() myQueue.isEmpty() myQueue.isEmpty myQueue {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		} if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			} ((Problem) myQueue.peek()).time > 0 ((Problem) myQueue.peek()).time ((Problem) myQueue.peek()) myQueue.peek myQueue ((Problem) myQueue.peek()).time 0 {
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			} if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				} ((Problem) myQueue.peek()).time > Required ((Problem) myQueue.peek()).time ((Problem) myQueue.peek()) myQueue.peek myQueue ((Problem) myQueue.peek()).time Required {
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				} currentItem = ((Problem) myQueue.peek()) currentItem ((Problem) myQueue.peek()) myQueue.peek myQueue myQueue.remove() myQueue.remove myQueue currentItem.time -= Required currentItem.time currentItem currentItem.time Required totalTime += Required totalTime Required myQueue.offer(currentItem) myQueue.offer myQueue currentItem {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				} currentItem = ((Problem) myQueue.peek()) currentItem ((Problem) myQueue.peek()) myQueue.peek myQueue myQueue.remove() myQueue.remove myQueue totalTime += currentItem.time totalTime currentItem.time currentItem currentItem.time System.out.println(currentItem.name + " " + totalTime) System.out.println System.out System System.out currentItem.name + " " + totalTime currentItem.name + " " + totalTime currentItem.name currentItem currentItem.name " " totalTime {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			} System.out.println(((Problem) myQueue.peek()).name + " " + totalTime) System.out.println System.out System System.out ((Problem) myQueue.peek()).name + " " + totalTime ((Problem) myQueue.peek()).name + " " + totalTime ((Problem) myQueue.peek()).name ((Problem) myQueue.peek()) myQueue.peek myQueue ((Problem) myQueue.peek()).name " " totalTime myQueue.remove() myQueue.remove myQueue String[] args args class Problem {
	String name;
	int time;
	public Problem(String name, int time){
		this.name = name;
		this.time = time;
	}
	} Problem String name; name int time; time public Problem(String name, int time){
		this.name = name;
		this.time = time;
	} Problem {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public class Main{
	String name;
	int time;
	static int totalTime = 0;


	

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String line = in.nextLine(); 
		String[] words = line.split(" ");
		Problem currentItem;
		Queue<Problem> myQueue = new LinkedList<Problem>();
		int pro = Integer.parseInt(words[0]);
		int Required = Integer.parseInt(words[1]);

		for(int i = 0; i < pro; i++) {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		}
		in.close();


		//System.out.println("StartQueue");
		while(!myQueue.isEmpty()) {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		}


	}
} public class Main{
	String name;
	int time;
	static int totalTime = 0;


	

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String line = in.nextLine(); 
		String[] words = line.split(" ");
		Problem currentItem;
		Queue<Problem> myQueue = new LinkedList<Problem>();
		int pro = Integer.parseInt(words[0]);
		int Required = Integer.parseInt(words[1]);

		for(int i = 0; i < pro; i++) {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		}
		in.close();


		//System.out.println("StartQueue");
		while(!myQueue.isEmpty()) {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		}


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

public class Main{
	String name;
	int time;
	static int totalTime = 0;


	

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String line = in.nextLine(); 
		String[] words = line.split(" ");
		Problem currentItem;
		Queue<Problem> myQueue = new LinkedList<Problem>();
		int pro = Integer.parseInt(words[0]);
		int Required = Integer.parseInt(words[1]);

		for(int i = 0; i < pro; i++) {
			line = in.nextLine(); 
			words = line.split(" ");
			myQueue.offer(new Problem(words[0], Integer.parseInt(words[1])));
			//System.out.println("added to queue: " + words[0]);
		}
		in.close();


		//System.out.println("StartQueue");
		while(!myQueue.isEmpty()) {
			//System.out.println("Queue Not Empty");
			if(((Problem) myQueue.peek()).time > 0){
				//System.out.println("IF1");
				if(((Problem) myQueue.peek()).time > Required){
					//System.out.println("IF2");
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					currentItem.time -= Required;
					totalTime += Required;
					myQueue.offer(currentItem);
				}else {
					currentItem = ((Problem) myQueue.peek()); 
					myQueue.remove();
					totalTime += currentItem.time;
					System.out.println(currentItem.name + " " + totalTime);
				}
			}else {
				System.out.println(((Problem) myQueue.peek()).name + " " + totalTime);
				myQueue.remove();

			}
		}


	}
}
	class Problem {
	String name;
	int time;
	public Problem(String name, int time){
		this.name = name;
		this.time = time;
	}
	}
