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