import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int q = scan.nextInt();
    	int[] tqueue = new int[n];
    	String[] nqueue = new String[n];
    	int start = 0;
    	int end = n - 1;
    	int now = 0;
    	int how = n;
    	
    	for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	}
    	
    	while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	}
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int q = scan.nextInt();
    	int[] tqueue = new int[n];
    	String[] nqueue = new String[n];
    	int start = 0;
    	int end = n - 1;
    	int now = 0;
    	int how = n;
    	
    	for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	}
    	
    	while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	}
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int q = scan.nextInt();
    	int[] tqueue = new int[n];
    	String[] nqueue = new String[n];
    	int start = 0;
    	int end = n - 1;
    	int now = 0;
    	int how = n;
    	
    	for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	}
    	
    	while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	}
    } main {
        Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int q = scan.nextInt();
    	int[] tqueue = new int[n];
    	String[] nqueue = new String[n];
    	int start = 0;
    	int end = n - 1;
    	int now = 0;
    	int how = n;
    	
    	for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	}
    	
    	while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	}
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan int[] tqueue = new int[n]; tqueue new int[n] n String[] nqueue = new String[n]; nqueue new String[n] n int start = 0; start 0 int end = n - 1; end n - 1 n 1 int now = 0; now 0 int how = n; how n for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	} {
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	} nqueue[i] = scan.next() nqueue[i] nqueue i scan.next() scan.next scan tqueue[i] = scan.nextInt() tqueue[i] tqueue i scan.nextInt() scan.nextInt scan while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	} how > 0 how 0 {
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	} if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		} tqueue[start] <= q tqueue[start] tqueue start q {
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		} now += tqueue[start] now tqueue[start] tqueue start System.out.println(nqueue[start]+" "+now) System.out.println System.out System System.out nqueue[start]+" "+now nqueue[start]+" "+now nqueue[start] nqueue start " " now start = (start + 1)%n start (start + 1)%n (start + 1) start 1 n how-- how {
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		} now += q now q end = (end + 1)%n end (end + 1)%n (end + 1) end 1 n tqueue[end] = tqueue[start] - q tqueue[end] tqueue end tqueue[start] - q tqueue[start] tqueue start q nqueue[end] = nqueue[start] nqueue[end] nqueue end nqueue[start] nqueue start start = (start + 1)%n start (start + 1)%n (start + 1) start 1 n String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int q = scan.nextInt();
    	int[] tqueue = new int[n];
    	String[] nqueue = new String[n];
    	int start = 0;
    	int end = n - 1;
    	int now = 0;
    	int how = n;
    	
    	for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	}
    	
    	while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	}
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int q = scan.nextInt();
    	int[] tqueue = new int[n];
    	String[] nqueue = new String[n];
    	int start = 0;
    	int end = n - 1;
    	int now = 0;
    	int how = n;
    	
    	for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	}
    	
    	while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	}
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int q = scan.nextInt();
    	int[] tqueue = new int[n];
    	String[] nqueue = new String[n];
    	int start = 0;
    	int end = n - 1;
    	int now = 0;
    	int how = n;
    	
    	for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	}
    	
    	while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	}
    }
}
