
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int tm=scan.nextInt();
		String stmp=scan.nextLine();
		Queue<Integer> q=new LinkedList<>();
		Queue<String> qstr=new LinkedList<>();
		
		for(int i=0;i<n;i++){
			String string=scan.nextLine();
			String[] str=string.split(" ");
			qstr.offer(str[0]);
			q.offer(Integer.parseInt(str[1]));
		}
		int round=0;
		int sum=0;
		while(!q.isEmpty()){
			int tmp=q.poll();
			if(tmp<=tm){
				sum+=tmp;
				System.out.print(qstr.poll()+" ");
				//System.out.println(round*tm+tmp%tm-com);
				System.out.println(sum);
			}
			else {
				q.offer(tmp-tm);
				qstr.offer(qstr.poll());
				sum+=tm;
			}
			round++;
		}
	}

}


/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