import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	int time = 0;
	void run() {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> Qi = new ArrayDeque<>();
		Deque<String> Qs = new ArrayDeque<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for(int i = 0; i < n; i++) {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		}
		while(!Qs.isEmpty()) {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		}
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Arrays; Arrays java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner java.util public class Main {
	int time = 0;
	void run() {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> Qi = new ArrayDeque<>();
		Deque<String> Qs = new ArrayDeque<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for(int i = 0; i < n; i++) {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		}
		while(!Qs.isEmpty()) {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		}
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
} Main int time = 0; time 0 void run() {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> Qi = new ArrayDeque<>();
		Deque<String> Qs = new ArrayDeque<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for(int i = 0; i < n; i++) {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		}
		while(!Qs.isEmpty()) {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		}
		
		sc.close();
	} run {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> Qi = new ArrayDeque<>();
		Deque<String> Qs = new ArrayDeque<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for(int i = 0; i < n; i++) {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		}
		while(!Qs.isEmpty()) {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		}
		
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Deque<Integer> Qi = new ArrayDeque<>(); Qi new ArrayDeque<>() Deque<String> Qs = new ArrayDeque<>(); Qs new ArrayDeque<>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc for(int i = 0; i < n; i++) {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		} {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		} Qs.addLast(sc.next()) Qs.addLast Qs sc.next() sc.next sc Qi.addLast(sc.nextInt()) Qi.addLast Qi sc.nextInt() sc.nextInt sc while(!Qs.isEmpty()) {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		} !Qs.isEmpty() Qs.isEmpty() Qs.isEmpty Qs {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		} int a = Qi.poll(); a Qi.poll() Qi.poll Qi String s = Qs.poll(); s Qs.poll() Qs.poll Qs if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			} a <= q a q {
				time += a;
				System.out.println(s + " " + time);
			} time += a time a System.out.println(s + " " + time) System.out.println System.out System System.out s + " " + time s + " " + time s " " time {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			} time += q time q Qs.addLast(s) Qs.addLast Qs s Qi.addLast(a - q) Qi.addLast Qi a - q a q sc.close() sc.close sc void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	} debug {
		System.out.println(Arrays.deepToString(o));
	} System.out.println(Arrays.deepToString(o)) System.out.println System.out System System.out Arrays.deepToString(o) Arrays.deepToString Arrays o Object... o o public static void main(String[] args) {
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args public class Main {
	int time = 0;
	void run() {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> Qi = new ArrayDeque<>();
		Deque<String> Qs = new ArrayDeque<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for(int i = 0; i < n; i++) {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		}
		while(!Qs.isEmpty()) {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		}
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
} public class Main {
	int time = 0;
	void run() {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> Qi = new ArrayDeque<>();
		Deque<String> Qs = new ArrayDeque<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for(int i = 0; i < n; i++) {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		}
		while(!Qs.isEmpty()) {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		}
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
} Main
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	int time = 0;
	void run() {
		Scanner sc = new Scanner(System.in);
		Deque<Integer> Qi = new ArrayDeque<>();
		Deque<String> Qs = new ArrayDeque<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for(int i = 0; i < n; i++) {
			Qs.addLast(sc.next());
			Qi.addLast(sc.nextInt());
		}
		while(!Qs.isEmpty()) {
			int a = Qi.poll();
			String s = Qs.poll();
			if(a <= q) {
				time += a;
				System.out.println(s + " " + time);
			}else {
				time += q;
				Qs.addLast(s);
				Qi.addLast(a - q);
			}
		}
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}
