import java.util.*;
public class Main {
	
	Scanner sc = new Scanner(System.in);
	int n,q;
	int nowtime=0;
	Integer process;
	String name;
	
	Queue<String> jobname = new ArrayDeque<String>();
	Queue<Integer> queue = new ArrayDeque<Integer>();
	
	Queue<String> finishjob = new ArrayDeque<String>();
	Queue<Integer> finish = new ArrayDeque<Integer>();
	
	public void input() {
		n = sc.nextInt();
		q = sc.nextInt();
		for(int i=0; i<n; i++) {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		}
	}
	
	public void queue() {
		while(true) {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		}
	}
	
	public void output() {
		while(true) {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.queue();
		obj.output();
	}
}
 import java.util.*; util.* java public class Main {
	
	Scanner sc = new Scanner(System.in);
	int n,q;
	int nowtime=0;
	Integer process;
	String name;
	
	Queue<String> jobname = new ArrayDeque<String>();
	Queue<Integer> queue = new ArrayDeque<Integer>();
	
	Queue<String> finishjob = new ArrayDeque<String>();
	Queue<Integer> finish = new ArrayDeque<Integer>();
	
	public void input() {
		n = sc.nextInt();
		q = sc.nextInt();
		for(int i=0; i<n; i++) {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		}
	}
	
	public void queue() {
		while(true) {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		}
	}
	
	public void output() {
		while(true) {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.queue();
		obj.output();
	}
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n q; q int nowtime=0; nowtime 0 Integer process; process String name; name Queue<String> jobname = new ArrayDeque<String>(); jobname new ArrayDeque<String>() Queue<Integer> queue = new ArrayDeque<Integer>(); queue new ArrayDeque<Integer>() Queue<String> finishjob = new ArrayDeque<String>(); finishjob new ArrayDeque<String>() Queue<Integer> finish = new ArrayDeque<Integer>(); finish new ArrayDeque<Integer>() public void input() {
		n = sc.nextInt();
		q = sc.nextInt();
		for(int i=0; i<n; i++) {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		}
	} input {
		n = sc.nextInt();
		q = sc.nextInt();
		for(int i=0; i<n; i++) {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		}
	} n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt() q sc.nextInt() sc.nextInt sc for(int i=0; i<n; i++) {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		} {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		} jobname.add( sc.next() ) jobname.add jobname sc.next() sc.next sc queue.add( sc.nextInt() ) queue.add queue sc.nextInt() sc.nextInt sc public void queue() {
		while(true) {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		}
	} queue {
		while(true) {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		}
	} while(true) {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		} true {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		} process = queue.poll() process queue.poll() queue.poll queue if(process == null) break; //キューがnullなら終了 process == null process null break; //キューがnullなら終了 if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			} q >= process q process { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			} nowtime += process nowtime process name = jobname.poll() name jobname.poll() jobname.poll jobname finish.add(nowtime) finish.add finish nowtime finishjob.add(name) finishjob.add finishjob name { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			} nowtime += q nowtime q name = jobname.poll() name jobname.poll() jobname.poll jobname queue.add( process-q ) queue.add queue process-q process q jobname.add(name) jobname.add jobname name public void output() {
		while(true) {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		}
	} output {
		while(true) {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		}
	} while(true) {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		} true {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		} name = finishjob.poll() name finishjob.poll() finishjob.poll finishjob process = finish.poll() process finish.poll() finish.poll finish if(name == null || process == null) break; name == null || process == null name == null name null process == null process null break; System.out.println(name+" "+process) System.out.println System.out System System.out name+" "+process name+" "+process name " " process public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.queue();
		obj.output();
	} main {
		Main obj = new Main();
		obj.input();
		obj.queue();
		obj.output();
	} Main obj = new Main(); obj new Main() obj.input() obj.input obj obj.queue() obj.queue obj obj.output() obj.output obj String[] args args public class Main {
	
	Scanner sc = new Scanner(System.in);
	int n,q;
	int nowtime=0;
	Integer process;
	String name;
	
	Queue<String> jobname = new ArrayDeque<String>();
	Queue<Integer> queue = new ArrayDeque<Integer>();
	
	Queue<String> finishjob = new ArrayDeque<String>();
	Queue<Integer> finish = new ArrayDeque<Integer>();
	
	public void input() {
		n = sc.nextInt();
		q = sc.nextInt();
		for(int i=0; i<n; i++) {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		}
	}
	
	public void queue() {
		while(true) {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		}
	}
	
	public void output() {
		while(true) {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.queue();
		obj.output();
	}
} public class Main {
	
	Scanner sc = new Scanner(System.in);
	int n,q;
	int nowtime=0;
	Integer process;
	String name;
	
	Queue<String> jobname = new ArrayDeque<String>();
	Queue<Integer> queue = new ArrayDeque<Integer>();
	
	Queue<String> finishjob = new ArrayDeque<String>();
	Queue<Integer> finish = new ArrayDeque<Integer>();
	
	public void input() {
		n = sc.nextInt();
		q = sc.nextInt();
		for(int i=0; i<n; i++) {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		}
	}
	
	public void queue() {
		while(true) {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		}
	}
	
	public void output() {
		while(true) {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.queue();
		obj.output();
	}
} Main
import java.util.*;
public class Main {
	
	Scanner sc = new Scanner(System.in);
	int n,q;
	int nowtime=0;
	Integer process;
	String name;
	
	Queue<String> jobname = new ArrayDeque<String>();
	Queue<Integer> queue = new ArrayDeque<Integer>();
	
	Queue<String> finishjob = new ArrayDeque<String>();
	Queue<Integer> finish = new ArrayDeque<Integer>();
	
	public void input() {
		n = sc.nextInt();
		q = sc.nextInt();
		for(int i=0; i<n; i++) {
			jobname.add( sc.next() );
			queue.add( sc.nextInt() );
		}
	}
	
	public void queue() {
		while(true) {
			process = queue.poll();
			if(process == null) break; //キューがnullなら終了
			if(q >= process) { //プロセスの終了
				nowtime += process;
				name = jobname.poll();
				finish.add(nowtime);
				finishjob.add(name);
			}else { //タイムクオンタムを超えた
				nowtime += q;
				name = jobname.poll();
				queue.add( process-q );
				jobname.add(name);
			}
		}
	}
	
	public void output() {
		while(true) {
			name = finishjob.poll();
			process = finish.poll();
			if(name == null || process == null) break;
			System.out.println(name+" "+process);
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.queue();
		obj.output();
	}
}

