import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();

		Queue<String> queP = new LinkedList<String>();
		Queue<Integer> queT = new LinkedList<Integer>();

		int timeCount = 0;

		for (int i=0; i<n; i++) {
			queP.add(stdIn.next());
			queT.add(stdIn.nextInt());
		}

		while (queP.size() != 0) {
			if (queT.peek() - q >0) {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			}else {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			}
		}
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();

		Queue<String> queP = new LinkedList<String>();
		Queue<Integer> queT = new LinkedList<Integer>();

		int timeCount = 0;

		for (int i=0; i<n; i++) {
			queP.add(stdIn.next());
			queT.add(stdIn.nextInt());
		}

		while (queP.size() != 0) {
			if (queT.peek() - q >0) {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			}else {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();

		Queue<String> queP = new LinkedList<String>();
		Queue<Integer> queT = new LinkedList<Integer>();

		int timeCount = 0;

		for (int i=0; i<n; i++) {
			queP.add(stdIn.next());
			queT.add(stdIn.nextInt());
		}

		while (queP.size() != 0) {
			if (queT.peek() - q >0) {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			}else {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			}
		}
	} main {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();

		Queue<String> queP = new LinkedList<String>();
		Queue<Integer> queT = new LinkedList<Integer>();

		int timeCount = 0;

		for (int i=0; i<n; i++) {
			queP.add(stdIn.next());
			queT.add(stdIn.nextInt());
		}

		while (queP.size() != 0) {
			if (queT.peek() - q >0) {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			}else {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			}
		}
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int q = stdIn.nextInt(); q stdIn.nextInt() stdIn.nextInt stdIn Queue<String> queP = new LinkedList<String>(); queP new LinkedList<String>() Queue<Integer> queT = new LinkedList<Integer>(); queT new LinkedList<Integer>() int timeCount = 0; timeCount 0 for (int i=0; i<n; i++) {
			queP.add(stdIn.next());
			queT.add(stdIn.nextInt());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			queP.add(stdIn.next());
			queT.add(stdIn.nextInt());
		} {
			queP.add(stdIn.next());
			queT.add(stdIn.nextInt());
		} queP.add(stdIn.next()) queP.add queP stdIn.next() stdIn.next stdIn queT.add(stdIn.nextInt()) queT.add queT stdIn.nextInt() stdIn.nextInt stdIn while (queP.size() != 0) {
			if (queT.peek() - q >0) {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			}else {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			}
		} queP.size() != 0 queP.size() queP.size queP 0 {
			if (queT.peek() - q >0) {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			}else {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			}
		} if (queT.peek() - q >0) {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			}else {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			} queT.peek() - q >0 queT.peek() - q queT.peek() queT.peek queT q 0 {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			} queP.add(queP.poll()) queP.add queP queP.poll() queP.poll queP queT.add(queT.poll()-q) queT.add queT queT.poll()-q queT.poll() queT.poll queT q timeCount += q timeCount q {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			} timeCount += queT.poll() timeCount queT.poll() queT.poll queT System.out.println(queP.poll()+" "+timeCount) System.out.println System.out System System.out queP.poll()+" "+timeCount queP.poll()+" "+timeCount queP.poll() queP.poll queP " " timeCount String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();

		Queue<String> queP = new LinkedList<String>();
		Queue<Integer> queT = new LinkedList<Integer>();

		int timeCount = 0;

		for (int i=0; i<n; i++) {
			queP.add(stdIn.next());
			queT.add(stdIn.nextInt());
		}

		while (queP.size() != 0) {
			if (queT.peek() - q >0) {
				queP.add(queP.poll());
				queT.add(queT.poll()-q);
				timeCount += q;
			}else {
				timeCount += queT.poll();
				System.out.println(queP.poll()+" "+timeCount);
			}
		}
	}
}