import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<String> qProcess = new LinkedList<String>();
		Queue<Integer> qTime = new LinkedList<Integer>();
		
		int totalTime = 0;
		
		for (int i = 0; i < n; i++) {
			qProcess.add(sc.next());
			qTime.add(sc.nextInt());
		}
		
		while (qProcess.size()>0) {
			if (qTime.peek() - q > 0) {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} else {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			}
		}
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<String> qProcess = new LinkedList<String>();
		Queue<Integer> qTime = new LinkedList<Integer>();
		
		int totalTime = 0;
		
		for (int i = 0; i < n; i++) {
			qProcess.add(sc.next());
			qTime.add(sc.nextInt());
		}
		
		while (qProcess.size()>0) {
			if (qTime.peek() - q > 0) {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} else {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<String> qProcess = new LinkedList<String>();
		Queue<Integer> qTime = new LinkedList<Integer>();
		
		int totalTime = 0;
		
		for (int i = 0; i < n; i++) {
			qProcess.add(sc.next());
			qTime.add(sc.nextInt());
		}
		
		while (qProcess.size()>0) {
			if (qTime.peek() - q > 0) {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} else {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<String> qProcess = new LinkedList<String>();
		Queue<Integer> qTime = new LinkedList<Integer>();
		
		int totalTime = 0;
		
		for (int i = 0; i < n; i++) {
			qProcess.add(sc.next());
			qTime.add(sc.nextInt());
		}
		
		while (qProcess.size()>0) {
			if (qTime.peek() - q > 0) {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} else {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Queue<String> qProcess = new LinkedList<String>(); qProcess new LinkedList<String>() Queue<Integer> qTime = new LinkedList<Integer>(); qTime new LinkedList<Integer>() int totalTime = 0; totalTime 0 for (int i = 0; i < n; i++) {
			qProcess.add(sc.next());
			qTime.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			qProcess.add(sc.next());
			qTime.add(sc.nextInt());
		} {
			qProcess.add(sc.next());
			qTime.add(sc.nextInt());
		} qProcess.add(sc.next()) qProcess.add qProcess sc.next() sc.next sc qTime.add(sc.nextInt()) qTime.add qTime sc.nextInt() sc.nextInt sc while (qProcess.size()>0) {
			if (qTime.peek() - q > 0) {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} else {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			}
		} qProcess.size()>0 qProcess.size() qProcess.size qProcess 0 {
			if (qTime.peek() - q > 0) {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} else {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			}
		} if (qTime.peek() - q > 0) {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} else {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			} qTime.peek() - q > 0 qTime.peek() - q qTime.peek() qTime.peek qTime q 0 {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} qProcess.add(qProcess.poll()) qProcess.add qProcess qProcess.poll() qProcess.poll qProcess qTime.add(qTime.poll()-q) qTime.add qTime qTime.poll()-q qTime.poll() qTime.poll qTime q totalTime = totalTime + q totalTime totalTime + q totalTime q {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			} totalTime = totalTime + qTime.poll() totalTime totalTime + qTime.poll() totalTime qTime.poll() qTime.poll qTime System.out.println(qProcess.poll() + ' ' + totalTime) System.out.println System.out System System.out qProcess.poll() + ' ' + totalTime qProcess.poll() + ' ' + totalTime qProcess.poll() qProcess.poll qProcess ' ' totalTime String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		Queue<String> qProcess = new LinkedList<String>();
		Queue<Integer> qTime = new LinkedList<Integer>();
		
		int totalTime = 0;
		
		for (int i = 0; i < n; i++) {
			qProcess.add(sc.next());
			qTime.add(sc.nextInt());
		}
		
		while (qProcess.size()>0) {
			if (qTime.peek() - q > 0) {
				qProcess.add(qProcess.poll());
				qTime.add(qTime.poll()-q);
				totalTime = totalTime + q;
			} else {
				totalTime = totalTime + qTime.poll();
				System.out.println(qProcess.poll() + ' ' + totalTime);
			}
		}
	}
}
