import java.util.*;
public class Main {
	public static void main(String [] args) {
		
		LinkedList<String> names = new LinkedList<String>();
		LinkedList<Integer> times = new LinkedList<Integer>();
		Scanner in = new Scanner(System.in);
		int numLines = in.nextInt();
		int t = in.nextInt();
		int totalTime = 0;
	
		for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		}
	}
	
}
 import java.util.*; util.* java public class Main {
	public static void main(String [] args) {
		
		LinkedList<String> names = new LinkedList<String>();
		LinkedList<Integer> times = new LinkedList<Integer>();
		Scanner in = new Scanner(System.in);
		int numLines = in.nextInt();
		int t = in.nextInt();
		int totalTime = 0;
	
		for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		}
	}
	
} Main public static void main(String [] args) {
		
		LinkedList<String> names = new LinkedList<String>();
		LinkedList<Integer> times = new LinkedList<Integer>();
		Scanner in = new Scanner(System.in);
		int numLines = in.nextInt();
		int t = in.nextInt();
		int totalTime = 0;
	
		for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		}
	} main {
		
		LinkedList<String> names = new LinkedList<String>();
		LinkedList<Integer> times = new LinkedList<Integer>();
		Scanner in = new Scanner(System.in);
		int numLines = in.nextInt();
		int t = in.nextInt();
		int totalTime = 0;
	
		for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		}
	} LinkedList<String> names = new LinkedList<String>(); names new LinkedList<String>() LinkedList<Integer> times = new LinkedList<Integer>(); times new LinkedList<Integer>() Scanner in = new Scanner(System.in); in new Scanner(System.in) int numLines = in.nextInt(); numLines in.nextInt() in.nextInt in int t = in.nextInt(); t in.nextInt() in.nextInt in int totalTime = 0; totalTime 0 for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		} int i = 0; int i = 0; i 0 i < numLines i numLines 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 while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		} !times.isEmpty() times.isEmpty() times.isEmpty times {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		} String name = names.removeFirst(); name names.removeFirst() names.removeFirst names int time = times.removeFirst(); time times.removeFirst() times.removeFirst times if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			} time <= t time t {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			} totalTime += time totalTime time System.out.println(name + " " + totalTime) System.out.println System.out System System.out name + " " + totalTime name + " " + totalTime name " " totalTime {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			} totalTime += t totalTime t names.addLast(name) names.addLast names name times.addLast(time - t) times.addLast times time - t time t String [] args args public class Main {
	public static void main(String [] args) {
		
		LinkedList<String> names = new LinkedList<String>();
		LinkedList<Integer> times = new LinkedList<Integer>();
		Scanner in = new Scanner(System.in);
		int numLines = in.nextInt();
		int t = in.nextInt();
		int totalTime = 0;
	
		for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		}
	}
	
} public class Main {
	public static void main(String [] args) {
		
		LinkedList<String> names = new LinkedList<String>();
		LinkedList<Integer> times = new LinkedList<Integer>();
		Scanner in = new Scanner(System.in);
		int numLines = in.nextInt();
		int t = in.nextInt();
		int totalTime = 0;
	
		for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		}
	}
	
} Main
import java.util.*;
public class Main {
	public static void main(String [] args) {
		
		LinkedList<String> names = new LinkedList<String>();
		LinkedList<Integer> times = new LinkedList<Integer>();
		Scanner in = new Scanner(System.in);
		int numLines = in.nextInt();
		int t = in.nextInt();
		int totalTime = 0;
	
		for(int i = 0; i < numLines; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		while(!times.isEmpty()) {
			String name = names.removeFirst();
			int time = times.removeFirst();
			
			if(time <= t) {
				totalTime += time;
				System.out.println(name + " " + totalTime);
			}
			
			else {
				totalTime += t;
				names.addLast(name);
				times.addLast(time - t);
			}
		}
	}
	
}

