import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		Deque<Process> deque = new ArrayDeque<>();
		String s;
		int a;
		for (int i=0; i<n; i++) {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		}
		int time = 0;
		int temp;
		while (deque.size()!=0) {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		}
	}
}

class Process {
	String name;
	int time;
	public Process (String n, int t) {
		this.name = n;
		this.time = t;
	}
	public String getName () {
		return this.name;
	}
	public int getTime () {
		return this.time;
	}
} import java.util.*; util.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		Deque<Process> deque = new ArrayDeque<>();
		String s;
		int a;
		for (int i=0; i<n; i++) {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		}
		int time = 0;
		int temp;
		while (deque.size()!=0) {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		}
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		Deque<Process> deque = new ArrayDeque<>();
		String s;
		int a;
		for (int i=0; i<n; i++) {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		}
		int time = 0;
		int temp;
		while (deque.size()!=0) {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		}
	} main {
		int n = sc.nextInt();
		int q = sc.nextInt();
		Deque<Process> deque = new ArrayDeque<>();
		String s;
		int a;
		for (int i=0; i<n; i++) {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		}
		int time = 0;
		int temp;
		while (deque.size()!=0) {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		}
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Deque<Process> deque = new ArrayDeque<>(); deque new ArrayDeque<>() String s; s int a; a for (int i=0; i<n; i++) {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		} {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		} s = sc.next() s sc.next() sc.next sc a = sc.nextInt() a sc.nextInt() sc.nextInt sc deque.addLast(new Process(s,a)) deque.addLast deque new Process(s,a) int time = 0; time 0 int temp; temp while (deque.size()!=0) {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		} deque.size()!=0 deque.size() deque.size deque 0 {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		} temp = Math.min(q,deque.getFirst().getTime()) temp Math.min(q,deque.getFirst().getTime()) Math.min Math q deque.getFirst().getTime() deque.getFirst().getTime deque.getFirst() deque.getFirst deque deque.getFirst().time -= temp deque.getFirst().time deque.getFirst() deque.getFirst deque deque.getFirst().time temp time += temp time temp if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);} deque.getFirst().getTime() > 0 deque.getFirst().getTime() deque.getFirst().getTime deque.getFirst() deque.getFirst deque 0 {
				deque.addLast(deque.removeFirst());
			} deque.addLast(deque.removeFirst()) deque.addLast deque deque.removeFirst() deque.removeFirst deque {out.println(deque.removeFirst().getName()+" "+time);} out.println(deque.removeFirst().getName()+" "+time) out.println out deque.removeFirst().getName()+" "+time deque.removeFirst().getName()+" "+time deque.removeFirst().getName() deque.removeFirst().getName deque.removeFirst() deque.removeFirst deque " " time String[] args args class Process {
	String name;
	int time;
	public Process (String n, int t) {
		this.name = n;
		this.time = t;
	}
	public String getName () {
		return this.name;
	}
	public int getTime () {
		return this.time;
	}
} Process String name; name int time; time public Process (String n, int t) {
		this.name = n;
		this.time = t;
	} Process {
		this.name = n;
		this.time = t;
	} this.name = n this.name this this.name n this.time = t this.time this this.time t String n n int t t public String getName () {
		return this.name;
	} getName {
		return this.name;
	} return this.name; this.name this this.name public int getTime () {
		return this.time;
	} getTime {
		return this.time;
	} return this.time; this.time this this.time public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		Deque<Process> deque = new ArrayDeque<>();
		String s;
		int a;
		for (int i=0; i<n; i++) {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		}
		int time = 0;
		int temp;
		while (deque.size()!=0) {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		}
	}
} public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		Deque<Process> deque = new ArrayDeque<>();
		String s;
		int a;
		for (int i=0; i<n; i++) {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		}
		int time = 0;
		int temp;
		while (deque.size()!=0) {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		}
	}
} Main
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		Deque<Process> deque = new ArrayDeque<>();
		String s;
		int a;
		for (int i=0; i<n; i++) {
			s = sc.next();
			a = sc.nextInt();
			deque.addLast(new Process(s,a));
		}
		int time = 0;
		int temp;
		while (deque.size()!=0) {
			temp = Math.min(q,deque.getFirst().getTime());
			deque.getFirst().time -= temp;
			time += temp;
			if (deque.getFirst().getTime() > 0) {
				deque.addLast(deque.removeFirst());
			}
			else {out.println(deque.removeFirst().getName()+" "+time);}
		}
	}
}

class Process {
	String name;
	int time;
	public Process (String n, int t) {
		this.name = n;
		this.time = t;
	}
	public String getName () {
		return this.name;
	}
	public int getTime () {
		return this.time;
	}
}
