
import java.util.Scanner;

public class Main {
	
	public static int size = 5;
	public static int interval = 100;
	
	public static int head=0, tail=0;
	
	public static boolean isFull() {
		return (tail-head >= size) ? true : false;
	}
	
	public static boolean isEmpty() {
		return (tail-head <=0 ) ? true : false;
	}

	public static void enqueue(Item[] queue, Item x) throws Exception {
		if (isFull()) 
			throw new Exception("Error: The queue is full!");
		queue[tail%size] = x;
		tail ++;
	}
	
	public static Item dequeue(Item[] queue) throws Exception {
		if (isEmpty())
			throw new Exception("Error: The queue is empty");
		Item headItem = queue[head%size];
		queue[head%size] = null;
		head ++;
		return headItem;
	}
	
	public static int process(Item i, int interval) {
		int time = i.getTime();
		if (time<=interval) {
			i.setTime(0);
			return time;
		} else {
			i.setTime(time-interval);
			return interval;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		size = sc.nextInt();
		interval = sc.nextInt();
		Item[] queue = new Item[size];
		
		int atime = 0;
		
		try {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

class Item {
	private String name;
	private int time;
	public String getName() {
		return name;
	}
	public int getTime() {
		return time;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setTime(int time) {
		this.time = time;
	}
	public Item(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	}
	
} import java.util.Scanner; Scanner java.util public class Main {
	
	public static int size = 5;
	public static int interval = 100;
	
	public static int head=0, tail=0;
	
	public static boolean isFull() {
		return (tail-head >= size) ? true : false;
	}
	
	public static boolean isEmpty() {
		return (tail-head <=0 ) ? true : false;
	}

	public static void enqueue(Item[] queue, Item x) throws Exception {
		if (isFull()) 
			throw new Exception("Error: The queue is full!");
		queue[tail%size] = x;
		tail ++;
	}
	
	public static Item dequeue(Item[] queue) throws Exception {
		if (isEmpty())
			throw new Exception("Error: The queue is empty");
		Item headItem = queue[head%size];
		queue[head%size] = null;
		head ++;
		return headItem;
	}
	
	public static int process(Item i, int interval) {
		int time = i.getTime();
		if (time<=interval) {
			i.setTime(0);
			return time;
		} else {
			i.setTime(time-interval);
			return interval;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		size = sc.nextInt();
		interval = sc.nextInt();
		Item[] queue = new Item[size];
		
		int atime = 0;
		
		try {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

} Main public static int size = 5; size 5 public static int interval = 100; interval 100 public static int head=0 head 0 tail=0; tail 0 public static boolean isFull() {
		return (tail-head >= size) ? true : false;
	} isFull {
		return (tail-head >= size) ? true : false;
	} return (tail-head >= size) ? true : false; (tail-head >= size) ? true : false (tail-head >= size) tail-head tail head size true false public static boolean isEmpty() {
		return (tail-head <=0 ) ? true : false;
	} isEmpty {
		return (tail-head <=0 ) ? true : false;
	} return (tail-head <=0 ) ? true : false; (tail-head <=0 ) ? true : false (tail-head <=0 ) tail-head tail head 0 true false public static void enqueue(Item[] queue, Item x) throws Exception {
		if (isFull()) 
			throw new Exception("Error: The queue is full!");
		queue[tail%size] = x;
		tail ++;
	} enqueue {
		if (isFull()) 
			throw new Exception("Error: The queue is full!");
		queue[tail%size] = x;
		tail ++;
	} if (isFull()) 
			throw new Exception("Error: The queue is full!"); isFull() isFull throw new Exception("Error: The queue is full!"); new Exception("Error: The queue is full!") queue[tail%size] = x queue[tail%size] queue tail%size tail size x tail ++ tail Item[] queue queue Item x x public static Item dequeue(Item[] queue) throws Exception {
		if (isEmpty())
			throw new Exception("Error: The queue is empty");
		Item headItem = queue[head%size];
		queue[head%size] = null;
		head ++;
		return headItem;
	} dequeue {
		if (isEmpty())
			throw new Exception("Error: The queue is empty");
		Item headItem = queue[head%size];
		queue[head%size] = null;
		head ++;
		return headItem;
	} if (isEmpty())
			throw new Exception("Error: The queue is empty"); isEmpty() isEmpty throw new Exception("Error: The queue is empty"); new Exception("Error: The queue is empty") Item headItem = queue[head%size]; headItem queue[head%size] queue head%size head size queue[head%size] = null queue[head%size] queue head%size head size null head ++ head return headItem; headItem Item[] queue queue public static int process(Item i, int interval) {
		int time = i.getTime();
		if (time<=interval) {
			i.setTime(0);
			return time;
		} else {
			i.setTime(time-interval);
			return interval;
		}
	} process {
		int time = i.getTime();
		if (time<=interval) {
			i.setTime(0);
			return time;
		} else {
			i.setTime(time-interval);
			return interval;
		}
	} int time = i.getTime(); time i.getTime() i.getTime i if (time<=interval) {
			i.setTime(0);
			return time;
		} else {
			i.setTime(time-interval);
			return interval;
		} time<=interval time interval {
			i.setTime(0);
			return time;
		} i.setTime(0) i.setTime i 0 return time; time {
			i.setTime(time-interval);
			return interval;
		} i.setTime(time-interval) i.setTime i time-interval time interval return interval; interval Item i i int interval interval public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		size = sc.nextInt();
		interval = sc.nextInt();
		Item[] queue = new Item[size];
		
		int atime = 0;
		
		try {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	} main {
		Scanner sc = new Scanner(System.in);
		size = sc.nextInt();
		interval = sc.nextInt();
		Item[] queue = new Item[size];
		
		int atime = 0;
		
		try {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) size = sc.nextInt() size sc.nextInt() sc.nextInt sc interval = sc.nextInt() interval sc.nextInt() sc.nextInt sc Item[] queue = new Item[size]; queue new Item[size] size int atime = 0; atime 0 try {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} Exception e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			} int i=0; int i=0; i 0 i<size i size i++ i++ i {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			} {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			} enqueue(queue, new Item(sc.next(), sc.nextInt())) enqueue queue new Item(sc.next(), sc.nextInt()) sc.close() sc.close sc while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			} !isEmpty() isEmpty() isEmpty {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			} Item item = dequeue(queue); item dequeue(queue) dequeue queue atime += process(item, interval) atime process(item, interval) process item interval if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				} item.getTime() == 0 item.getTime() item.getTime item 0 {
					System.out.println(item.getName() + " " + atime);
				} System.out.println(item.getName() + " " + atime) System.out.println System.out System System.out item.getName() + " " + atime item.getName() + " " + atime item.getName() item.getName item " " atime {
					enqueue(queue, item);
				} enqueue(queue, item) enqueue queue item String[] args args class Item {
	private String name;
	private int time;
	public String getName() {
		return name;
	}
	public int getTime() {
		return time;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setTime(int time) {
		this.time = time;
	}
	public Item(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	}
	
} Item private String name; name private int time; time public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public int getTime() {
		return time;
	} getTime {
		return time;
	} return time; time public void setName(String name) {
		this.name = name;
	} setName {
		this.name = name;
	} this.name = name this.name this this.name name String name name public void setTime(int time) {
		this.time = time;
	} setTime {
		this.time = time;
	} this.time = time this.time this this.time time int time time public Item(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	} Item {
		super();
		this.name = name;
		this.time = time;
	} super() super 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 {
	
	public static int size = 5;
	public static int interval = 100;
	
	public static int head=0, tail=0;
	
	public static boolean isFull() {
		return (tail-head >= size) ? true : false;
	}
	
	public static boolean isEmpty() {
		return (tail-head <=0 ) ? true : false;
	}

	public static void enqueue(Item[] queue, Item x) throws Exception {
		if (isFull()) 
			throw new Exception("Error: The queue is full!");
		queue[tail%size] = x;
		tail ++;
	}
	
	public static Item dequeue(Item[] queue) throws Exception {
		if (isEmpty())
			throw new Exception("Error: The queue is empty");
		Item headItem = queue[head%size];
		queue[head%size] = null;
		head ++;
		return headItem;
	}
	
	public static int process(Item i, int interval) {
		int time = i.getTime();
		if (time<=interval) {
			i.setTime(0);
			return time;
		} else {
			i.setTime(time-interval);
			return interval;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		size = sc.nextInt();
		interval = sc.nextInt();
		Item[] queue = new Item[size];
		
		int atime = 0;
		
		try {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

} public class Main {
	
	public static int size = 5;
	public static int interval = 100;
	
	public static int head=0, tail=0;
	
	public static boolean isFull() {
		return (tail-head >= size) ? true : false;
	}
	
	public static boolean isEmpty() {
		return (tail-head <=0 ) ? true : false;
	}

	public static void enqueue(Item[] queue, Item x) throws Exception {
		if (isFull()) 
			throw new Exception("Error: The queue is full!");
		queue[tail%size] = x;
		tail ++;
	}
	
	public static Item dequeue(Item[] queue) throws Exception {
		if (isEmpty())
			throw new Exception("Error: The queue is empty");
		Item headItem = queue[head%size];
		queue[head%size] = null;
		head ++;
		return headItem;
	}
	
	public static int process(Item i, int interval) {
		int time = i.getTime();
		if (time<=interval) {
			i.setTime(0);
			return time;
		} else {
			i.setTime(time-interval);
			return interval;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		size = sc.nextInt();
		interval = sc.nextInt();
		Item[] queue = new Item[size];
		
		int atime = 0;
		
		try {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

} Main

import java.util.Scanner;

public class Main {
	
	public static int size = 5;
	public static int interval = 100;
	
	public static int head=0, tail=0;
	
	public static boolean isFull() {
		return (tail-head >= size) ? true : false;
	}
	
	public static boolean isEmpty() {
		return (tail-head <=0 ) ? true : false;
	}

	public static void enqueue(Item[] queue, Item x) throws Exception {
		if (isFull()) 
			throw new Exception("Error: The queue is full!");
		queue[tail%size] = x;
		tail ++;
	}
	
	public static Item dequeue(Item[] queue) throws Exception {
		if (isEmpty())
			throw new Exception("Error: The queue is empty");
		Item headItem = queue[head%size];
		queue[head%size] = null;
		head ++;
		return headItem;
	}
	
	public static int process(Item i, int interval) {
		int time = i.getTime();
		if (time<=interval) {
			i.setTime(0);
			return time;
		} else {
			i.setTime(time-interval);
			return interval;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		size = sc.nextInt();
		interval = sc.nextInt();
		Item[] queue = new Item[size];
		
		int atime = 0;
		
		try {
			for (int i=0; i<size; i++) {
				enqueue(queue, new Item(sc.next(), sc.nextInt()));
			}
			sc.close();
			
			while (!isEmpty()) {
				Item item = dequeue(queue);
				atime += process(item, interval);
				if (item.getTime() == 0) {
					System.out.println(item.getName() + " " + atime);
				} else {
					enqueue(queue, item);
				}
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

class Item {
	private String name;
	private int time;
	public String getName() {
		return name;
	}
	public int getTime() {
		return time;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setTime(int time) {
		this.time = time;
	}
	public Item(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	}
	
}
