import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		mathClass keisan;
		Scanner scan = new Scanner(System.in);
		int queueAmount = scan.nextInt();
		int qTime = scan.nextInt();
		int totalTime = 0;
		int amari = 0;
		int[] proNum = new int[queueAmount+1];	//?????°?????????????????????1????????¨??????
		String[] proID = new String[queueAmount+1];

		for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		}
		int dataTop = 0;
		int dataBottom = queueAmount-1;
		proNum[queueAmount] = 0;
		
		while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		}




	}
}
class mathClass{

	public mathClass(){

	}

	//?????????????????????
	public int shisokuEnzan(String stringX,String stringY,String op){
		int ret =0;
		int x =Integer.parseInt(stringX);
		int y =Integer.parseInt(stringY);
//		System.out.println(x+" "+op+" "+y+" wo okonau");

		if(op.charAt(0) == '+'){
			ret = x + y;
		}
		if(op.charAt(0) == '-'){
			ret = x - y;
		}
		if(op.charAt(0) == '*'){
			ret = x * y;
		}
		if(op.charAt(0) == '/'){
			ret = x / y;
		}
		return ret;
	}

	//???????????¨?????????
	public void disp(int[] ary){
		for(int i=0;i<ary.length;i++){
			System.out.println(ary[i]);
		}
	}

}
/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