import java.util.Scanner;


import java.util.*;
import java.util.LinkedList;
import java.util.Queue;

class Pair{
	public String key;
	public int value;
	public Pair(String name, int number) {
		this.key = name;
		this.value = number;
	}
}

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] info = sc.nextLine().split(" ");
		
		int n = Integer.parseInt(info[0]);
		int limit =Integer.parseInt(info[1]);
		int time = 0;
		
		Queue<Pair> q = new LinkedList<Pair>();
		String [] inputArrayS = new String[n];
		for (int i = 0; i < n; i += 1) {
			inputArrayS[i]  = sc.nextLine();
		}
		sc.close();
		
		for (int j = 0; j < n; j += 1) {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			}

			while (q.size()>0) {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			}
		}
	} import java.util.Scanner; Scanner java.util import java.util.*; util.* java import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util class Pair{
	public String key;
	public int value;
	public Pair(String name, int number) {
		this.key = name;
		this.value = number;
	}
} Pair public String key; key public int value; value public Pair(String name, int number) {
		this.key = name;
		this.value = number;
	} Pair {
		this.key = name;
		this.value = number;
	} this.key = name this.key this this.key name this.value = number this.value this this.value number String name name int number number public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] info = sc.nextLine().split(" ");
		
		int n = Integer.parseInt(info[0]);
		int limit =Integer.parseInt(info[1]);
		int time = 0;
		
		Queue<Pair> q = new LinkedList<Pair>();
		String [] inputArrayS = new String[n];
		for (int i = 0; i < n; i += 1) {
			inputArrayS[i]  = sc.nextLine();
		}
		sc.close();
		
		for (int j = 0; j < n; j += 1) {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			}

			while (q.size()>0) {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			}
		}
	} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] info = sc.nextLine().split(" ");
		
		int n = Integer.parseInt(info[0]);
		int limit =Integer.parseInt(info[1]);
		int time = 0;
		
		Queue<Pair> q = new LinkedList<Pair>();
		String [] inputArrayS = new String[n];
		for (int i = 0; i < n; i += 1) {
			inputArrayS[i]  = sc.nextLine();
		}
		sc.close();
		
		for (int j = 0; j < n; j += 1) {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			}

			while (q.size()>0) {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			}
		} main {
		Scanner sc = new Scanner(System.in);
		String[] info = sc.nextLine().split(" ");
		
		int n = Integer.parseInt(info[0]);
		int limit =Integer.parseInt(info[1]);
		int time = 0;
		
		Queue<Pair> q = new LinkedList<Pair>();
		String [] inputArrayS = new String[n];
		for (int i = 0; i < n; i += 1) {
			inputArrayS[i]  = sc.nextLine();
		}
		sc.close();
		
		for (int j = 0; j < n; j += 1) {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			}

			while (q.size()>0) {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			}
		} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] info = sc.nextLine().split(" "); info sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int n = Integer.parseInt(info[0]); n Integer.parseInt(info[0]) Integer.parseInt Integer info[0] info 0 int limit =Integer.parseInt(info[1]); limit Integer.parseInt(info[1]) Integer.parseInt Integer info[1] info 1 int time = 0; time 0 Queue<Pair> q = new LinkedList<Pair>(); q new LinkedList<Pair>() String [] inputArrayS = new String[n]; inputArrayS new String[n] n for (int i = 0; i < n; i += 1) {
			inputArrayS[i]  = sc.nextLine();
		} int i = 0; int i = 0; i 0 i < n i n i += 1 i += 1 i 1 {
			inputArrayS[i]  = sc.nextLine();
		} {
			inputArrayS[i]  = sc.nextLine();
		} inputArrayS[i]  = sc.nextLine() inputArrayS[i] inputArrayS i sc.nextLine() sc.nextLine sc sc.close() sc.close sc for (int j = 0; j < n; j += 1) {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			} int j = 0; int j = 0; j 0 j < n j n j += 1 j += 1 j 1 {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			} {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			} int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]); quantum Integer.parseInt(inputArrayS[j].split(" ")[1]) Integer.parseInt Integer inputArrayS[j].split(" ")[1] inputArrayS[j].split(" ") inputArrayS[j].split inputArrayS[j] inputArrayS j " " 1 String nameS = inputArrayS[j].split(" ")[0]; nameS inputArrayS[j].split(" ")[0] inputArrayS[j].split(" ") inputArrayS[j].split inputArrayS[j] inputArrayS j " " 0 Pair p = new Pair(nameS, quantum); p new Pair(nameS, quantum) q.offer(p) q.offer q p while (q.size()>0) {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			} q.size()>0 q.size() q.size q 0 {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			} if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				} q.peek().value > limit q.peek().value q.peek() q.peek q q.peek().value limit {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				} Pair cp = q.remove(); cp q.remove() q.remove q time = time + limit time time + limit time limit cp.value = cp.value - limit cp.value cp cp.value cp.value - limit cp.value cp cp.value limit cp.key = cp.key cp.key cp cp.key cp.key cp cp.key q.add(cp) q.add q cp {
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				} time = time + q.peek().value time time + q.peek().value time q.peek().value q.peek() q.peek q q.peek().value System.out.println(q.peek().key + " " + time) System.out.println System.out System System.out q.peek().key + " " + time q.peek().key + " " + time q.peek().key q.peek() q.peek q q.peek().key " " time q.remove() q.remove q String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] info = sc.nextLine().split(" ");
		
		int n = Integer.parseInt(info[0]);
		int limit =Integer.parseInt(info[1]);
		int time = 0;
		
		Queue<Pair> q = new LinkedList<Pair>();
		String [] inputArrayS = new String[n];
		for (int i = 0; i < n; i += 1) {
			inputArrayS[i]  = sc.nextLine();
		}
		sc.close();
		
		for (int j = 0; j < n; j += 1) {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			}

			while (q.size()>0) {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			}
		}
	} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] info = sc.nextLine().split(" ");
		
		int n = Integer.parseInt(info[0]);
		int limit =Integer.parseInt(info[1]);
		int time = 0;
		
		Queue<Pair> q = new LinkedList<Pair>();
		String [] inputArrayS = new String[n];
		for (int i = 0; i < n; i += 1) {
			inputArrayS[i]  = sc.nextLine();
		}
		sc.close();
		
		for (int j = 0; j < n; j += 1) {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			}

			while (q.size()>0) {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			}
		}
	} Main
import java.util.Scanner;


import java.util.*;
import java.util.LinkedList;
import java.util.Queue;

class Pair{
	public String key;
	public int value;
	public Pair(String name, int number) {
		this.key = name;
		this.value = number;
	}
}

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] info = sc.nextLine().split(" ");
		
		int n = Integer.parseInt(info[0]);
		int limit =Integer.parseInt(info[1]);
		int time = 0;
		
		Queue<Pair> q = new LinkedList<Pair>();
		String [] inputArrayS = new String[n];
		for (int i = 0; i < n; i += 1) {
			inputArrayS[i]  = sc.nextLine();
		}
		sc.close();
		
		for (int j = 0; j < n; j += 1) {
			
			int quantum = Integer.parseInt(inputArrayS[j].split(" ")[1]);
			String nameS = inputArrayS[j].split(" ")[0];
			Pair p = new Pair(nameS, quantum);
			q.offer(p);
			}

			while (q.size()>0) {
				
					if(q.peek().value > limit) {
						Pair cp = q.remove();
						time = time + limit;
						
					
					cp.value = cp.value - limit;
					cp.key = cp.key;	
					q.add(cp);
					
					
				}else{
					
					time = time + q.peek().value;				
					System.out.println(q.peek().key + " " + time);
					q.remove();
					
				}
			}
		}
	}
