import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

// ALDS1_3_B
public class Main {
	public static void calc(Queue<Info> qu, int q) {
		Info info;
		int time = 0;
		while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue<Info> qu = new LinkedList<Info>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		}
		calc(qu, q);
		sc.close();
	}
}

class Info {
	String name;
	int time;
	Info(String name, int time) {
		this.name = name;
		this.time = time;
	}
	Info() {}
} import java.util.Scanner; Scanner java.util import java.util.Queue; Queue java.util import java.util.LinkedList; LinkedList java.util public class Main {
	public static void calc(Queue<Info> qu, int q) {
		Info info;
		int time = 0;
		while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue<Info> qu = new LinkedList<Info>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		}
		calc(qu, q);
		sc.close();
	}
} Main public static void calc(Queue<Info> qu, int q) {
		Info info;
		int time = 0;
		while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		}
	} calc {
		Info info;
		int time = 0;
		while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		}
	} Info info; info int time = 0; time 0 while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		} !qu.isEmpty() qu.isEmpty() qu.isEmpty qu {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		} info = qu.remove() info qu.remove() qu.remove qu if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			} info.time - q > 0 info.time - q info.time info info.time q 0 {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} info.time = info.time - q info.time info info.time info.time - q info.time info info.time q qu.add(info) qu.add qu info time += q time q {
				time += info.time;
				System.out.println(info.name + " " + time);
			} time += info.time time info.time info info.time System.out.println(info.name + " " + time) System.out.println System.out System System.out info.name + " " + time info.name + " " + time info.name info info.name " " time Queue<Info> qu qu int q q public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue<Info> qu = new LinkedList<Info>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		}
		calc(qu, q);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		Queue<Info> qu = new LinkedList<Info>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		}
		calc(qu, q);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<Info> qu = new LinkedList<Info>(); qu new LinkedList<Info>() 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++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			qu.add(new Info(sc.next(), sc.nextInt()));
		} {
			qu.add(new Info(sc.next(), sc.nextInt()));
		} qu.add(new Info(sc.next(), sc.nextInt())) qu.add qu new Info(sc.next(), sc.nextInt()) calc(qu, q) calc qu q sc.close() sc.close sc String[] args args class Info {
	String name;
	int time;
	Info(String name, int time) {
		this.name = name;
		this.time = time;
	}
	Info() {}
} Info String name; name int time; time Info(String name, int time) {
		this.name = name;
		this.time = time;
	} Info {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time Info() {} Info {} public class Main {
	public static void calc(Queue<Info> qu, int q) {
		Info info;
		int time = 0;
		while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue<Info> qu = new LinkedList<Info>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		}
		calc(qu, q);
		sc.close();
	}
} public class Main {
	public static void calc(Queue<Info> qu, int q) {
		Info info;
		int time = 0;
		while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue<Info> qu = new LinkedList<Info>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		}
		calc(qu, q);
		sc.close();
	}
} Main
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

// ALDS1_3_B
public class Main {
	public static void calc(Queue<Info> qu, int q) {
		Info info;
		int time = 0;
		while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue<Info> qu = new LinkedList<Info>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		}
		calc(qu, q);
		sc.close();
	}
}

class Info {
	String name;
	int time;
	Info(String name, int time) {
		this.name = name;
		this.time = time;
	}
	Info() {}
}
