import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		Queue<Integer> queue = new ArrayDeque<Integer>();
		Queue<String> name = new ArrayDeque<String>();
		int N = sc.nextInt();
		int q = sc.nextInt();
		int tlen = 0;
		for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		}
	}	
} import java.util.Queue; Queue java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.Scanner; Scanner java.util public class Main {
	
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		Queue<Integer> queue = new ArrayDeque<Integer>();
		Queue<String> name = new ArrayDeque<String>();
		int N = sc.nextInt();
		int q = sc.nextInt();
		int tlen = 0;
		for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		}
	}	
} Main public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		Queue<Integer> queue = new ArrayDeque<Integer>();
		Queue<String> name = new ArrayDeque<String>();
		int N = sc.nextInt();
		int q = sc.nextInt();
		int tlen = 0;
		for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		Queue<Integer> queue = new ArrayDeque<Integer>();
		Queue<String> name = new ArrayDeque<String>();
		int N = sc.nextInt();
		int q = sc.nextInt();
		int tlen = 0;
		for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<Integer> queue = new ArrayDeque<Integer>(); queue new ArrayDeque<Integer>() Queue<String> name = new ArrayDeque<String>(); name new ArrayDeque<String>() int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc int tlen = 0; tlen 0 for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			name.add(sc.next());
			queue.add(sc.nextInt());
		} {
			name.add(sc.next());
			queue.add(sc.nextInt());
		} name.add(sc.next()) name.add name sc.next() sc.next sc queue.add(sc.nextInt()) queue.add queue sc.nextInt() sc.nextInt sc while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		} queue.size()!=0 queue.size() queue.size queue 0 {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		} if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			} queue.element() > q queue.element() queue.element queue q {
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} tlen += q tlen q queue.add(queue.element() - q) queue.add queue queue.element() - q queue.element() queue.element queue q queue.remove() queue.remove queue name.add(name.element()) name.add name name.element() name.element name name.remove() name.remove name {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			} tlen += queue.element() tlen queue.element() queue.element queue System.out.println(name.element()+" "+tlen) System.out.println System.out System System.out name.element()+" "+tlen name.element()+" "+tlen name.element() name.element name " " tlen queue.remove() queue.remove queue name.remove() name.remove name String arg[] arg public class Main {
	
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		Queue<Integer> queue = new ArrayDeque<Integer>();
		Queue<String> name = new ArrayDeque<String>();
		int N = sc.nextInt();
		int q = sc.nextInt();
		int tlen = 0;
		for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		}
	}	
} public class Main {
	
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		Queue<Integer> queue = new ArrayDeque<Integer>();
		Queue<String> name = new ArrayDeque<String>();
		int N = sc.nextInt();
		int q = sc.nextInt();
		int tlen = 0;
		for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		}
	}	
} Main
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		Queue<Integer> queue = new ArrayDeque<Integer>();
		Queue<String> name = new ArrayDeque<String>();
		int N = sc.nextInt();
		int q = sc.nextInt();
		int tlen = 0;
		for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		}
	}	
}
