import java.util.Scanner;
class Queue{
	String name="";
	int time;
	public Queue(String str,int t) {
		name=str;
		time=t;
	}
	public void Show() {
		System.out.println(name+" "+time);
	}
}

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,j,n,q,t,count=0;
        String str="";
        n=scan.nextInt();
        q=scan.nextInt();
        Queue[] queue=new Queue[n];
        for(i=0;i<n;i++) {
        	str=scan.next();
        	t=scan.nextInt();
        	queue[i]=new Queue(str,t);
        }
        i=0;
        t=0;
        while(n>=0) {
        	if(queue[i].time>q) {
        		queue[i].time-=q;
        		t+=q;
        	}
        	else {
        		t+=queue[i].time;
            	System.out.println(queue[i].name+" "+t);
        		for(j=i;j<n-1;j++) {
        			queue[j]=queue[j+1];
        		}
        		i--;
        		n--;
        	}
        	if(count==n)break;
        	i++;
        	if(i>=n) {
        		i=0;
        	}
        }
	}
}

/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