import java.util.*;

public class Main {
	public static void main(String[] args) {
		int n = 0, q = 0;
		Scanner scanner = new Scanner(System.in);
		try {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} catch (Exception e) {
		}
		ArrayList<Queue> qu = new ArrayList<Queue>();
		for (int i = 0; i < n; i++) {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		}

		int i = 0, count = 0, alltime = 0;
		while (qu.size() > 0) {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		}

	}
}


class Queue {
	String name;
	int time;

	public Queue(String n, int t) {
		name = n;
		time = t;
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		int n = 0, q = 0;
		Scanner scanner = new Scanner(System.in);
		try {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} catch (Exception e) {
		}
		ArrayList<Queue> qu = new ArrayList<Queue>();
		for (int i = 0; i < n; i++) {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		}

		int i = 0, count = 0, alltime = 0;
		while (qu.size() > 0) {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		}

	}
} Main public static void main(String[] args) {
		int n = 0, q = 0;
		Scanner scanner = new Scanner(System.in);
		try {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} catch (Exception e) {
		}
		ArrayList<Queue> qu = new ArrayList<Queue>();
		for (int i = 0; i < n; i++) {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		}

		int i = 0, count = 0, alltime = 0;
		while (qu.size() > 0) {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		}

	} main {
		int n = 0, q = 0;
		Scanner scanner = new Scanner(System.in);
		try {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} catch (Exception e) {
		}
		ArrayList<Queue> qu = new ArrayList<Queue>();
		for (int i = 0; i < n; i++) {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		}

		int i = 0, count = 0, alltime = 0;
		while (qu.size() > 0) {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		}

	} int n = 0 n 0 q = 0; q 0 Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) try {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} catch (Exception e) {
		} catch (Exception e) {
		} Exception e {
		} {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} n = scanner.nextInt() n scanner.nextInt() scanner.nextInt scanner q = scanner.nextInt() q scanner.nextInt() scanner.nextInt scanner ArrayList<Queue> qu = new ArrayList<Queue>(); qu new ArrayList<Queue>() for (int i = 0; i < n; i++) {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		} {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		} try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			} catch (Exception e) {
			} Exception e {
			} {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} String name = scanner.next(); name scanner.next() scanner.next scanner int time = scanner.nextInt(); time scanner.nextInt() scanner.nextInt scanner qu.add(new Queue(name, time)) qu.add qu new Queue(name, time) int i = 0 i 0 count = 0 count 0 alltime = 0; alltime 0 while (qu.size() > 0) {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		} qu.size() > 0 qu.size() qu.size qu 0 {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		} i = i % qu.size() i i % qu.size() i qu.size() qu.size qu int t = qu.get(i).time; t qu.get(i).time qu.get(i) qu.get qu i qu.get(i).time if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			} t <= q t q {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} alltime += t alltime t System.out.println(qu.get(i).name + " " + alltime) System.out.println System.out System System.out qu.get(i).name + " " + alltime qu.get(i).name + " " + alltime qu.get(i).name qu.get(i) qu.get qu i qu.get(i).name " " alltime qu.remove(i) qu.remove qu i i-- i {
				alltime += q;
				qu.get(i).time -= q;
			} alltime += q alltime q qu.get(i).time -= q qu.get(i).time qu.get(i) qu.get qu i qu.get(i).time q i++ i String[] args args class Queue {
	String name;
	int time;

	public Queue(String n, int t) {
		name = n;
		time = t;
	}
} Queue String name; name int time; time public Queue(String n, int t) {
		name = n;
		time = t;
	} Queue {
		name = n;
		time = t;
	} name = n name n time = t time t String n n int t t public class Main {
	public static void main(String[] args) {
		int n = 0, q = 0;
		Scanner scanner = new Scanner(System.in);
		try {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} catch (Exception e) {
		}
		ArrayList<Queue> qu = new ArrayList<Queue>();
		for (int i = 0; i < n; i++) {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		}

		int i = 0, count = 0, alltime = 0;
		while (qu.size() > 0) {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		}

	}
} public class Main {
	public static void main(String[] args) {
		int n = 0, q = 0;
		Scanner scanner = new Scanner(System.in);
		try {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} catch (Exception e) {
		}
		ArrayList<Queue> qu = new ArrayList<Queue>();
		for (int i = 0; i < n; i++) {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		}

		int i = 0, count = 0, alltime = 0;
		while (qu.size() > 0) {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		}

	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int n = 0, q = 0;
		Scanner scanner = new Scanner(System.in);
		try {
			n = scanner.nextInt();
			q = scanner.nextInt();
		} catch (Exception e) {
		}
		ArrayList<Queue> qu = new ArrayList<Queue>();
		for (int i = 0; i < n; i++) {
			try {
				String name = scanner.next();
				int time = scanner.nextInt();
				qu.add(new Queue(name, time));
			} catch (Exception e) {
			}
		}

		int i = 0, count = 0, alltime = 0;
		while (qu.size() > 0) {
			i = i % qu.size();
			int t = qu.get(i).time;
			if (t <= q) {
				alltime += t;
				System.out.println(qu.get(i).name + " " + alltime);
				qu.remove(i);
				i--;
			} else {
				alltime += q;
				qu.get(i).time -= q;
			}
			i++;
		}

	}
}


class Queue {
	String name;
	int time;

	public Queue(String n, int t) {
		name = n;
		time = t;
	}
}