import java.io.*;
import java.util.Arrays;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] fst = (br.readLine()).split(" ");
		int n = Integer.parseInt(fst[0]);
		int quan = Integer.parseInt(fst[1]);
		int sumtime = 0;
		Deque<Integer> stackint = new ArrayDeque<Integer>();
		Deque<String> stackst = new ArrayDeque<String>();
		for ( int i = 0; i<n ; i++ ) {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		}
		int a;
		String b;
		try{
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		}catch (NullPointerException e){
				// System.out.println("d");

		}
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz