import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Process> queue = new ArrayDeque<Process>();
		String[] str01 = br.readLine().split(" ");
		int n = Integer.parseInt(str01[0]);
		int point = Integer.parseInt(str01[1]);
		int sumTime = 0;
		

		for (int i = 0; i < n; i++) {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		}
		int i = 0;
		while (true) {
			Process temp = queue.poll();
			if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			}
		}
	}
}

class Process {
	String name;
	int time;

	Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Process> queue = new ArrayDeque<Process>();
		String[] str01 = br.readLine().split(" ");
		int n = Integer.parseInt(str01[0]);
		int point = Integer.parseInt(str01[1]);
		int sumTime = 0;
		

		for (int i = 0; i < n; i++) {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		}
		int i = 0;
		while (true) {
			Process temp = queue.poll();
			if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			}
		}
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Process> queue = new ArrayDeque<Process>();
		String[] str01 = br.readLine().split(" ");
		int n = Integer.parseInt(str01[0]);
		int point = Integer.parseInt(str01[1]);
		int sumTime = 0;
		

		for (int i = 0; i < n; i++) {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		}
		int i = 0;
		while (true) {
			Process temp = queue.poll();
			if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Process> queue = new ArrayDeque<Process>();
		String[] str01 = br.readLine().split(" ");
		int n = Integer.parseInt(str01[0]);
		int point = Integer.parseInt(str01[1]);
		int sumTime = 0;
		

		for (int i = 0; i < n; i++) {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		}
		int i = 0;
		while (true) {
			Process temp = queue.poll();
			if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) ArrayDeque<Process> queue = new ArrayDeque<Process>(); queue new ArrayDeque<Process>() String[] str01 = br.readLine().split(" "); str01 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(str01[0]); n Integer.parseInt(str01[0]) Integer.parseInt Integer str01[0] str01 0 int point = Integer.parseInt(str01[1]); point Integer.parseInt(str01[1]) Integer.parseInt Integer str01[1] str01 1 int sumTime = 0; sumTime 0 for (int i = 0; i < n; i++) {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		} {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		} String[] str02 = br.readLine().split(" "); str02 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " Process process = new Process(str02[0], Integer.parseInt(str02[1])); process new Process(str02[0], Integer.parseInt(str02[1])) queue.add(process) queue.add queue process int i = 0; i 0 while (true) {
			Process temp = queue.poll();
			if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			}
		} true {
			Process temp = queue.poll();
			if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			}
		} Process temp = queue.poll(); temp queue.poll() queue.poll queue if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			} temp.time <= point temp.time temp temp.time point {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} sumTime = sumTime + temp.time sumTime sumTime + temp.time sumTime temp.time temp temp.time temp.time = sumTime temp.time temp temp.time sumTime System.out.println(temp.name + " " + temp.time) System.out.println System.out System System.out temp.name + " " + temp.time temp.name + " " + temp.time temp.name temp temp.name " " temp.time temp temp.time i++ i if(i == n){
					break;
				} i == n i n {
					break;
				} break; {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			} temp.time = temp.time - point temp.time temp temp.time temp.time - point temp.time temp temp.time point queue.add(temp) queue.add queue temp sumTime = sumTime + point sumTime sumTime + point sumTime point String[] args args class Process {
	String name;
	int time;

	Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
} Process String name; name int time; time Process(String name, int time) {
		this.name = name;
		this.time = time;
	} Process {
		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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Process> queue = new ArrayDeque<Process>();
		String[] str01 = br.readLine().split(" ");
		int n = Integer.parseInt(str01[0]);
		int point = Integer.parseInt(str01[1]);
		int sumTime = 0;
		

		for (int i = 0; i < n; i++) {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		}
		int i = 0;
		while (true) {
			Process temp = queue.poll();
			if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			}
		}
	}
}

class Process {
	String name;
	int time;

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