

import java.util.*;

public class Main {
	public static void main(String args[]) {
		Queue<ItemPair> list = new LinkedList<ItemPair>();
		Scanner k = new Scanner(System.in);
		
		int processes = k.nextInt();
		int quantum = k.nextInt();
		
		//Fill the queue
		for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		}
		
		int timeStart = 0;
		while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		}
		
	}
}

//Each node in the queue will have these properties
class ItemPair {
	String name;
	int time;
	
	public ItemPair(int x, String y) {
		time = x;
		name = y;
	}
	public void set_time(int newTime) {
		this.time = newTime;
	}
	public int send_time() {
		return time;
	}
	public String send_name() {
		return name;
	}
	
	
	
}
 import java.util.*; util.* java public class Main {
	public static void main(String args[]) {
		Queue<ItemPair> list = new LinkedList<ItemPair>();
		Scanner k = new Scanner(System.in);
		
		int processes = k.nextInt();
		int quantum = k.nextInt();
		
		//Fill the queue
		for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		}
		
		int timeStart = 0;
		while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		}
		
	}
} Main public static void main(String args[]) {
		Queue<ItemPair> list = new LinkedList<ItemPair>();
		Scanner k = new Scanner(System.in);
		
		int processes = k.nextInt();
		int quantum = k.nextInt();
		
		//Fill the queue
		for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		}
		
		int timeStart = 0;
		while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		}
		
	} main {
		Queue<ItemPair> list = new LinkedList<ItemPair>();
		Scanner k = new Scanner(System.in);
		
		int processes = k.nextInt();
		int quantum = k.nextInt();
		
		//Fill the queue
		for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		}
		
		int timeStart = 0;
		while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		}
		
	} Queue<ItemPair> list = new LinkedList<ItemPair>(); list new LinkedList<ItemPair>() Scanner k = new Scanner(System.in); k new Scanner(System.in) int processes = k.nextInt(); processes k.nextInt() k.nextInt k int quantum = k.nextInt(); quantum k.nextInt() k.nextInt k for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		} int x = 0; int x = 0; x 0 x < processes x processes x++ x++ x {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		} {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		} String inputName = k.next(); inputName k.next() k.next k int inputTime = k.nextInt(); inputTime k.nextInt() k.nextInt k ItemPair itemPair = new ItemPair(inputTime, inputName); itemPair new ItemPair(inputTime, inputName) list.add(itemPair) list.add list itemPair int timeStart = 0; timeStart 0 while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		} !list.isEmpty() list.isEmpty() list.isEmpty list {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		} ItemPair temp = list.poll(); temp list.poll() list.poll list if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			} temp.send_time() > quantum temp.send_time() temp.send_time temp quantum {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} temp.set_time(temp.send_time() - quantum) temp.set_time temp temp.send_time() - quantum temp.send_time() temp.send_time temp quantum timeStart += quantum timeStart quantum list.add(temp) list.add list temp {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			} timeStart += temp.send_time() timeStart temp.send_time() temp.send_time temp System.out.println(temp.send_name() + " " + timeStart) System.out.println System.out System System.out temp.send_name() + " " + timeStart temp.send_name() + " " + timeStart temp.send_name() temp.send_name temp " " timeStart String args[] args class ItemPair {
	String name;
	int time;
	
	public ItemPair(int x, String y) {
		time = x;
		name = y;
	}
	public void set_time(int newTime) {
		this.time = newTime;
	}
	public int send_time() {
		return time;
	}
	public String send_name() {
		return name;
	}
	
	
	
} ItemPair String name; name int time; time public ItemPair(int x, String y) {
		time = x;
		name = y;
	} ItemPair {
		time = x;
		name = y;
	} time = x time x name = y name y int x x String y y public void set_time(int newTime) {
		this.time = newTime;
	} set_time {
		this.time = newTime;
	} this.time = newTime this.time this this.time newTime int newTime newTime public int send_time() {
		return time;
	} send_time {
		return time;
	} return time; time public String send_name() {
		return name;
	} send_name {
		return name;
	} return name; name public class Main {
	public static void main(String args[]) {
		Queue<ItemPair> list = new LinkedList<ItemPair>();
		Scanner k = new Scanner(System.in);
		
		int processes = k.nextInt();
		int quantum = k.nextInt();
		
		//Fill the queue
		for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		}
		
		int timeStart = 0;
		while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		}
		
	}
} public class Main {
	public static void main(String args[]) {
		Queue<ItemPair> list = new LinkedList<ItemPair>();
		Scanner k = new Scanner(System.in);
		
		int processes = k.nextInt();
		int quantum = k.nextInt();
		
		//Fill the queue
		for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		}
		
		int timeStart = 0;
		while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		}
		
	}
} Main


import java.util.*;

public class Main {
	public static void main(String args[]) {
		Queue<ItemPair> list = new LinkedList<ItemPair>();
		Scanner k = new Scanner(System.in);
		
		int processes = k.nextInt();
		int quantum = k.nextInt();
		
		//Fill the queue
		for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		}
		
		int timeStart = 0;
		while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		}
		
	}
}

//Each node in the queue will have these properties
class ItemPair {
	String name;
	int time;
	
	public ItemPair(int x, String y) {
		time = x;
		name = y;
	}
	public void set_time(int newTime) {
		this.time = newTime;
	}
	public int send_time() {
		return time;
	}
	public String send_name() {
		return name;
	}
	
	
	
}

