import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int quantum = in.nextInt();
		
		Queue<String> names = new LinkedList<String>();
		Queue<Integer> times = new LinkedList<Integer>();
		
		for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		int totTime = 0;
		Queue<String> resultNames = new LinkedList<String>();
		Queue<Integer> resultTimes = new LinkedList<Integer>();
		
		while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		}
		
		for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		}
		
		in.close();
		
	}

}
 import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int quantum = in.nextInt();
		
		Queue<String> names = new LinkedList<String>();
		Queue<Integer> times = new LinkedList<Integer>();
		
		for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		int totTime = 0;
		Queue<String> resultNames = new LinkedList<String>();
		Queue<Integer> resultTimes = new LinkedList<Integer>();
		
		while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		}
		
		for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		}
		
		in.close();
		
	}

} Main public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int quantum = in.nextInt();
		
		Queue<String> names = new LinkedList<String>();
		Queue<Integer> times = new LinkedList<Integer>();
		
		for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		int totTime = 0;
		Queue<String> resultNames = new LinkedList<String>();
		Queue<Integer> resultTimes = new LinkedList<Integer>();
		
		while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		}
		
		for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		}
		
		in.close();
		
	} main {
		
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int quantum = in.nextInt();
		
		Queue<String> names = new LinkedList<String>();
		Queue<Integer> times = new LinkedList<Integer>();
		
		for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		int totTime = 0;
		Queue<String> resultNames = new LinkedList<String>();
		Queue<Integer> resultTimes = new LinkedList<Integer>();
		
		while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		}
		
		for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		}
		
		in.close();
		
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int num = in.nextInt(); num in.nextInt() in.nextInt in int quantum = in.nextInt(); quantum in.nextInt() in.nextInt in Queue<String> names = new LinkedList<String>(); names new LinkedList<String>() Queue<Integer> times = new LinkedList<Integer>(); times new LinkedList<Integer>() for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			names.add(in.next());
			times.add(in.nextInt());
		} {
			names.add(in.next());
			times.add(in.nextInt());
		} names.add(in.next()) names.add names in.next() in.next in times.add(in.nextInt()) times.add times in.nextInt() in.nextInt in int totTime = 0; totTime 0 Queue<String> resultNames = new LinkedList<String>(); resultNames new LinkedList<String>() Queue<Integer> resultTimes = new LinkedList<Integer>(); resultTimes new LinkedList<Integer>() while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		} !names.isEmpty() names.isEmpty() names.isEmpty names {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		} int tempTime = times.remove(); tempTime times.remove() times.remove times if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			} tempTime <= quantum tempTime quantum {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} totTime += tempTime totTime tempTime resultNames.add(names.remove()) resultNames.add resultNames names.remove() names.remove names resultTimes.add(totTime) resultTimes.add resultTimes totTime {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			} totTime += quantum totTime quantum names.add(names.remove()) names.add names names.remove() names.remove names times.add(tempTime - quantum) times.add times tempTime - quantum tempTime quantum for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		} {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		} System.out.println(resultNames.remove() + " " + resultTimes.remove()) System.out.println System.out System System.out resultNames.remove() + " " + resultTimes.remove() resultNames.remove() + " " + resultTimes.remove() resultNames.remove() resultNames.remove resultNames " " resultTimes.remove() resultTimes.remove resultTimes in.close() in.close in String[] args args public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int quantum = in.nextInt();
		
		Queue<String> names = new LinkedList<String>();
		Queue<Integer> times = new LinkedList<Integer>();
		
		for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		int totTime = 0;
		Queue<String> resultNames = new LinkedList<String>();
		Queue<Integer> resultTimes = new LinkedList<Integer>();
		
		while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		}
		
		for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		}
		
		in.close();
		
	}

} public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int quantum = in.nextInt();
		
		Queue<String> names = new LinkedList<String>();
		Queue<Integer> times = new LinkedList<Integer>();
		
		for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		int totTime = 0;
		Queue<String> resultNames = new LinkedList<String>();
		Queue<Integer> resultTimes = new LinkedList<Integer>();
		
		while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		}
		
		for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		}
		
		in.close();
		
	}

} Main
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int quantum = in.nextInt();
		
		Queue<String> names = new LinkedList<String>();
		Queue<Integer> times = new LinkedList<Integer>();
		
		for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		int totTime = 0;
		Queue<String> resultNames = new LinkedList<String>();
		Queue<Integer> resultTimes = new LinkedList<Integer>();
		
		while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		}
		
		for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		}
		
		in.close();
		
	}

}

