import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] head = str.split(" ", 2);
		int n = Integer.parseInt(head[0]); // ????????????????????°
		int q = Integer.parseInt(head[1]); // ???????????????
		str = br.readLine();
		List<String> name = new ArrayList<>();
		List<Integer> time = new ArrayList<>();
		int top = 0;
		int end = 0;
		int clock = 0;
		for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		}
		while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] head = str.split(" ", 2);
		int n = Integer.parseInt(head[0]); // ????????????????????°
		int q = Integer.parseInt(head[1]); // ???????????????
		str = br.readLine();
		List<String> name = new ArrayList<>();
		List<Integer> time = new ArrayList<>();
		int top = 0;
		int end = 0;
		int clock = 0;
		for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		}
		while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		}
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] head = str.split(" ", 2);
		int n = Integer.parseInt(head[0]); // ????????????????????°
		int q = Integer.parseInt(head[1]); // ???????????????
		str = br.readLine();
		List<String> name = new ArrayList<>();
		List<Integer> time = new ArrayList<>();
		int top = 0;
		int end = 0;
		int clock = 0;
		for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		}
		while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] head = str.split(" ", 2);
		int n = Integer.parseInt(head[0]); // ????????????????????°
		int q = Integer.parseInt(head[1]); // ???????????????
		str = br.readLine();
		List<String> name = new ArrayList<>();
		List<Integer> time = new ArrayList<>();
		int top = 0;
		int end = 0;
		int clock = 0;
		for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		}
		while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str = br.readLine(); str br.readLine() br.readLine br String[] head = str.split(" ", 2); head str.split(" ", 2) str.split str " " 2 int n = Integer.parseInt(head[0]); n Integer.parseInt(head[0]) Integer.parseInt Integer head[0] head 0 int q = Integer.parseInt(head[1]); q Integer.parseInt(head[1]) Integer.parseInt Integer head[1] head 1 str = br.readLine() str br.readLine() br.readLine br List<String> name = new ArrayList<>(); name new ArrayList<>() List<Integer> time = new ArrayList<>(); time new ArrayList<>() int top = 0; top 0 int end = 0; end 0 int clock = 0; clock 0 for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		} {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		} String[] data = str.split(" ", 2); data str.split(" ", 2) str.split str " " 2 name.add(data[0]) name.add name data[0] data 0 time.add(Integer.parseInt(data[1])) time.add time Integer.parseInt(data[1]) Integer.parseInt Integer data[1] data 1 end++ end str = br.readLine() str br.readLine() br.readLine br while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		} top == 0 || top != end top == 0 top 0 top != end top end {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		} if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			} time.get(top) > q time.get(top) time.get time top q {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} time.add(time.get(top) - q) time.add time time.get(top) - q time.get(top) time.get time top q name.add(name.get(top)) name.add name name.get(top) name.get name top top++ top end++ end clock = clock + q clock clock + q clock q {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			} clock = clock + time.get(top) clock clock + time.get(top) clock time.get(top) time.get time top System.out.println(name.get(top) + " " + clock) System.out.println System.out System System.out name.get(top) + " " + clock name.get(top) + " " + clock name.get(top) name.get name top " " clock top++ top String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] head = str.split(" ", 2);
		int n = Integer.parseInt(head[0]); // ????????????????????°
		int q = Integer.parseInt(head[1]); // ???????????????
		str = br.readLine();
		List<String> name = new ArrayList<>();
		List<Integer> time = new ArrayList<>();
		int top = 0;
		int end = 0;
		int clock = 0;
		for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		}
		while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		}
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] head = str.split(" ", 2);
		int n = Integer.parseInt(head[0]); // ????????????????????°
		int q = Integer.parseInt(head[1]); // ???????????????
		str = br.readLine();
		List<String> name = new ArrayList<>();
		List<Integer> time = new ArrayList<>();
		int top = 0;
		int end = 0;
		int clock = 0;
		for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		}
		while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] head = str.split(" ", 2);
		int n = Integer.parseInt(head[0]); // ????????????????????°
		int q = Integer.parseInt(head[1]); // ???????????????
		str = br.readLine();
		List<String> name = new ArrayList<>();
		List<Integer> time = new ArrayList<>();
		int top = 0;
		int end = 0;
		int clock = 0;
		for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		}
		while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		}
	}
}