
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.ConcurrentLinkedQueue;

class Main {

	/*
	 * 最初は10番目のテストケースでTLEになったのがショックでした
	 */

	public static void main(String[] args) throws Exception {
		//入力と準備
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(br.readLine());
		int n = Integer.parseInt(scanner.next());
		int quantum = Integer.parseInt(scanner.next());
		scanner.close();
		String name[] = new String[n];
		int time[] = new int[n];
		Queue<Integer> queue = new ConcurrentLinkedQueue<Integer>();
		for(int i=0; i<n; i++) {
			scanner = new Scanner(br.readLine());
			name[i] = scanner.next();
			time[i] = Integer.parseInt(scanner.next());
			scanner.close();
			queue.add(i);
		}
		int currentTime =  0;
		//順に処理
		for(;!queue.isEmpty();) {
			Integer taskNo = queue.poll();
			time[taskNo] -= quantum;
			currentTime += quantum;
			if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			}
			queue.add(taskNo);
		}

	}

}

 import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util import java.util.concurrent.ConcurrentLinkedQueue; ConcurrentLinkedQueue java.util.concurrent class Main {

	/*
	 * 最初は10番目のテストケースでTLEになったのがショックでした
	 */

	public static void main(String[] args) throws Exception {
		//入力と準備
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(br.readLine());
		int n = Integer.parseInt(scanner.next());
		int quantum = Integer.parseInt(scanner.next());
		scanner.close();
		String name[] = new String[n];
		int time[] = new int[n];
		Queue<Integer> queue = new ConcurrentLinkedQueue<Integer>();
		for(int i=0; i<n; i++) {
			scanner = new Scanner(br.readLine());
			name[i] = scanner.next();
			time[i] = Integer.parseInt(scanner.next());
			scanner.close();
			queue.add(i);
		}
		int currentTime =  0;
		//順に処理
		for(;!queue.isEmpty();) {
			Integer taskNo = queue.poll();
			time[taskNo] -= quantum;
			currentTime += quantum;
			if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			}
			queue.add(taskNo);
		}

	}

} Main public static void main(String[] args) throws Exception {
		//入力と準備
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(br.readLine());
		int n = Integer.parseInt(scanner.next());
		int quantum = Integer.parseInt(scanner.next());
		scanner.close();
		String name[] = new String[n];
		int time[] = new int[n];
		Queue<Integer> queue = new ConcurrentLinkedQueue<Integer>();
		for(int i=0; i<n; i++) {
			scanner = new Scanner(br.readLine());
			name[i] = scanner.next();
			time[i] = Integer.parseInt(scanner.next());
			scanner.close();
			queue.add(i);
		}
		int currentTime =  0;
		//順に処理
		for(;!queue.isEmpty();) {
			Integer taskNo = queue.poll();
			time[taskNo] -= quantum;
			currentTime += quantum;
			if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			}
			queue.add(taskNo);
		}

	} main {
		//入力と準備
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(br.readLine());
		int n = Integer.parseInt(scanner.next());
		int quantum = Integer.parseInt(scanner.next());
		scanner.close();
		String name[] = new String[n];
		int time[] = new int[n];
		Queue<Integer> queue = new ConcurrentLinkedQueue<Integer>();
		for(int i=0; i<n; i++) {
			scanner = new Scanner(br.readLine());
			name[i] = scanner.next();
			time[i] = Integer.parseInt(scanner.next());
			scanner.close();
			queue.add(i);
		}
		int currentTime =  0;
		//順に処理
		for(;!queue.isEmpty();) {
			Integer taskNo = queue.poll();
			time[taskNo] -= quantum;
			currentTime += quantum;
			if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			}
			queue.add(taskNo);
		}

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Scanner scanner = new Scanner(br.readLine()); scanner new Scanner(br.readLine()) int n = Integer.parseInt(scanner.next()); n Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int quantum = Integer.parseInt(scanner.next()); quantum Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner scanner.close() scanner.close scanner String name[] = new String[n]; name new String[n] n int time[] = new int[n]; time new int[n] n Queue<Integer> queue = new ConcurrentLinkedQueue<Integer>(); queue new ConcurrentLinkedQueue<Integer>() for(int i=0; i<n; i++) {
			scanner = new Scanner(br.readLine());
			name[i] = scanner.next();
			time[i] = Integer.parseInt(scanner.next());
			scanner.close();
			queue.add(i);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			scanner = new Scanner(br.readLine());
			name[i] = scanner.next();
			time[i] = Integer.parseInt(scanner.next());
			scanner.close();
			queue.add(i);
		} {
			scanner = new Scanner(br.readLine());
			name[i] = scanner.next();
			time[i] = Integer.parseInt(scanner.next());
			scanner.close();
			queue.add(i);
		} scanner = new Scanner(br.readLine()) scanner new Scanner(br.readLine()) name[i] = scanner.next() name[i] name i scanner.next() scanner.next scanner time[i] = Integer.parseInt(scanner.next()) time[i] time i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner scanner.close() scanner.close scanner queue.add(i) queue.add queue i int currentTime =  0; currentTime 0 for(;!queue.isEmpty();) {
			Integer taskNo = queue.poll();
			time[taskNo] -= quantum;
			currentTime += quantum;
			if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			}
			queue.add(taskNo);
		} ; !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			Integer taskNo = queue.poll();
			time[taskNo] -= quantum;
			currentTime += quantum;
			if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			}
			queue.add(taskNo);
		} {
			Integer taskNo = queue.poll();
			time[taskNo] -= quantum;
			currentTime += quantum;
			if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			}
			queue.add(taskNo);
		} Integer taskNo = queue.poll(); taskNo queue.poll() queue.poll queue time[taskNo] -= quantum time[taskNo] time taskNo quantum currentTime += quantum currentTime quantum if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			} time[taskNo] <= 0 time[taskNo] time taskNo 0 {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			} currentTime += time[taskNo] currentTime time[taskNo] time taskNo System.out.println(name[taskNo]+" "+String.valueOf(currentTime)) System.out.println System.out System System.out name[taskNo]+" "+String.valueOf(currentTime) name[taskNo]+" "+String.valueOf(currentTime) name[taskNo] name taskNo " " String.valueOf(currentTime) String.valueOf String currentTime continue; queue.add(taskNo) queue.add queue taskNo String[] args args

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.ConcurrentLinkedQueue;

class Main {

	/*
	 * 最初は10番目のテストケースでTLEになったのがショックでした
	 */

	public static void main(String[] args) throws Exception {
		//入力と準備
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(br.readLine());
		int n = Integer.parseInt(scanner.next());
		int quantum = Integer.parseInt(scanner.next());
		scanner.close();
		String name[] = new String[n];
		int time[] = new int[n];
		Queue<Integer> queue = new ConcurrentLinkedQueue<Integer>();
		for(int i=0; i<n; i++) {
			scanner = new Scanner(br.readLine());
			name[i] = scanner.next();
			time[i] = Integer.parseInt(scanner.next());
			scanner.close();
			queue.add(i);
		}
		int currentTime =  0;
		//順に処理
		for(;!queue.isEmpty();) {
			Integer taskNo = queue.poll();
			time[taskNo] -= quantum;
			currentTime += quantum;
			if(time[taskNo] <= 0) {
				currentTime += time[taskNo];//超過しているので戻す
				System.out.println(name[taskNo]+" "+String.valueOf(currentTime));
				continue;
			}
			queue.add(taskNo);
		}

	}

}


