import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int timecount =0;
		int count = sc.nextInt();
		int max   = sc.nextInt();

		Queue<String> queName = new LinkedList<String>();
		Queue<Integer> queTime = new LinkedList<Integer>();

		for(int i=0; i<count; i++) {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		}

		while(queName.size() !=0) {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		}




	}
}

 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int timecount =0;
		int count = sc.nextInt();
		int max   = sc.nextInt();

		Queue<String> queName = new LinkedList<String>();
		Queue<Integer> queTime = new LinkedList<Integer>();

		for(int i=0; i<count; i++) {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		}

		while(queName.size() !=0) {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		}




	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int timecount =0;
		int count = sc.nextInt();
		int max   = sc.nextInt();

		Queue<String> queName = new LinkedList<String>();
		Queue<Integer> queTime = new LinkedList<Integer>();

		for(int i=0; i<count; i++) {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		}

		while(queName.size() !=0) {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		}




	} main {
		Scanner sc = new Scanner(System.in);
		int timecount =0;
		int count = sc.nextInt();
		int max   = sc.nextInt();

		Queue<String> queName = new LinkedList<String>();
		Queue<Integer> queTime = new LinkedList<Integer>();

		for(int i=0; i<count; i++) {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		}

		while(queName.size() !=0) {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		}




	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int timecount =0; timecount 0 int count = sc.nextInt(); count sc.nextInt() sc.nextInt sc int max   = sc.nextInt(); max sc.nextInt() sc.nextInt sc Queue<String> queName = new LinkedList<String>(); queName new LinkedList<String>() Queue<Integer> queTime = new LinkedList<Integer>(); queTime new LinkedList<Integer>() for(int i=0; i<count; i++) {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		} int i=0; int i=0; i 0 i<count i count i++ i++ i {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		} {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		} queName.add(sc.next()) queName.add queName sc.next() sc.next sc queTime.add(sc.nextInt()) queTime.add queTime sc.nextInt() sc.nextInt sc while(queName.size() !=0) {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		} queName.size() !=0 queName.size() queName.size queName 0 {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		} if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			} queTime.peek()-max>0 queTime.peek()-max queTime.peek() queTime.peek queTime max 0 {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			} queName.add(queName.poll()) queName.add queName queName.poll() queName.poll queName queTime.add(queTime.poll()-max) queTime.add queTime queTime.poll()-max queTime.poll() queTime.poll queTime max timecount +=max timecount max {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			} timecount += queTime.poll() timecount queTime.poll() queTime.poll queTime System.out.println(queName.poll()+" "+timecount) System.out.println System.out System System.out queName.poll()+" "+timecount queName.poll()+" "+timecount queName.poll() queName.poll queName " " timecount String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int timecount =0;
		int count = sc.nextInt();
		int max   = sc.nextInt();

		Queue<String> queName = new LinkedList<String>();
		Queue<Integer> queTime = new LinkedList<Integer>();

		for(int i=0; i<count; i++) {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		}

		while(queName.size() !=0) {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		}




	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int timecount =0;
		int count = sc.nextInt();
		int max   = sc.nextInt();

		Queue<String> queName = new LinkedList<String>();
		Queue<Integer> queTime = new LinkedList<Integer>();

		for(int i=0; i<count; i++) {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		}

		while(queName.size() !=0) {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		}




	}
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int timecount =0;
		int count = sc.nextInt();
		int max   = sc.nextInt();

		Queue<String> queName = new LinkedList<String>();
		Queue<Integer> queTime = new LinkedList<Integer>();

		for(int i=0; i<count; i++) {
			queName.add(sc.next());
			queTime.add(sc.nextInt());
		}

		while(queName.size() !=0) {
			if(queTime.peek()-max>0) {
				queName.add(queName.poll());
				queTime.add(queTime.poll()-max);
				timecount +=max;
			}else {
				timecount += queTime.poll();
				System.out.println(queName.poll()+" "+timecount);
			}

		}




	}
}


