import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int ma = line.indexOf(" ");
        int jobAmount = Integer.parseInt(line.substring(0, ma));
        int quantum = Integer.parseInt(line.substring(ma+1));
        
        ArrayList<String> lingerJob = new ArrayList<String>();
        ArrayList<Integer> lingerTime = new ArrayList<Integer>();
        
        for(int i=0;i<jobAmount;i++){
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        }
        
        
        
        int nowTime=0;
        
        while(lingerJob.size()!=0){
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int ma = line.indexOf(" ");
        int jobAmount = Integer.parseInt(line.substring(0, ma));
        int quantum = Integer.parseInt(line.substring(ma+1));
        
        ArrayList<String> lingerJob = new ArrayList<String>();
        ArrayList<Integer> lingerTime = new ArrayList<Integer>();
        
        for(int i=0;i<jobAmount;i++){
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        }
        
        
        
        int nowTime=0;
        
        while(lingerJob.size()!=0){
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int ma = line.indexOf(" ");
        int jobAmount = Integer.parseInt(line.substring(0, ma));
        int quantum = Integer.parseInt(line.substring(ma+1));
        
        ArrayList<String> lingerJob = new ArrayList<String>();
        ArrayList<Integer> lingerTime = new ArrayList<Integer>();
        
        for(int i=0;i<jobAmount;i++){
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        }
        
        
        
        int nowTime=0;
        
        while(lingerJob.size()!=0){
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int ma = line.indexOf(" ");
        int jobAmount = Integer.parseInt(line.substring(0, ma));
        int quantum = Integer.parseInt(line.substring(ma+1));
        
        ArrayList<String> lingerJob = new ArrayList<String>();
        ArrayList<Integer> lingerTime = new ArrayList<Integer>();
        
        for(int i=0;i<jobAmount;i++){
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        }
        
        
        
        int nowTime=0;
        
        while(lingerJob.size()!=0){
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int ma = line.indexOf(" "); ma line.indexOf(" ") line.indexOf line " " int jobAmount = Integer.parseInt(line.substring(0, ma)); jobAmount Integer.parseInt(line.substring(0, ma)) Integer.parseInt Integer line.substring(0, ma) line.substring line 0 ma int quantum = Integer.parseInt(line.substring(ma+1)); quantum Integer.parseInt(line.substring(ma+1)) Integer.parseInt Integer line.substring(ma+1) line.substring line ma+1 ma 1 ArrayList<String> lingerJob = new ArrayList<String>(); lingerJob new ArrayList<String>() ArrayList<Integer> lingerTime = new ArrayList<Integer>(); lingerTime new ArrayList<Integer>() for(int i=0;i<jobAmount;i++){
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        } int i=0; int i=0; i 0 i<jobAmount i jobAmount i++ i++ i {
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        } {
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        } String line2 = sc.nextLine(); line2 sc.nextLine() sc.nextLine sc int ma2 = line2.indexOf(" "); ma2 line2.indexOf(" ") line2.indexOf line2 " " lingerJob.add(line2.substring(0, ma2)) lingerJob.add lingerJob line2.substring(0, ma2) line2.substring line2 0 ma2 lingerTime.add(Integer.parseInt(line2.substring(ma2+1))) lingerTime.add lingerTime Integer.parseInt(line2.substring(ma2+1)) Integer.parseInt Integer line2.substring(ma2+1) line2.substring line2 ma2+1 ma2 1 int nowTime=0; nowTime 0 while(lingerJob.size()!=0){
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        } lingerJob.size()!=0 lingerJob.size() lingerJob.size lingerJob 0 {
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        } if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	} lingerTime.get(0)>quantum lingerTime.get(0) lingerTime.get lingerTime 0 quantum {
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	} lingerJob.add(lingerJob.get(0)) lingerJob.add lingerJob lingerJob.get(0) lingerJob.get lingerJob 0 lingerJob.remove(0) lingerJob.remove lingerJob 0 lingerTime.add(lingerTime.get(0)-quantum) lingerTime.add lingerTime lingerTime.get(0)-quantum lingerTime.get(0) lingerTime.get lingerTime 0 quantum lingerTime.remove(0) lingerTime.remove lingerTime 0 nowTime+=quantum nowTime quantum {
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	} nowTime+=lingerTime.get(0) nowTime lingerTime.get(0) lingerTime.get lingerTime 0 System.out.println(lingerJob.get(0)+" "+nowTime) System.out.println System.out System System.out lingerJob.get(0)+" "+nowTime lingerJob.get(0)+" "+nowTime lingerJob.get(0) lingerJob.get lingerJob 0 " " nowTime lingerJob.remove(0) lingerJob.remove lingerJob 0 lingerTime.remove(0) lingerTime.remove lingerTime 0 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int ma = line.indexOf(" ");
        int jobAmount = Integer.parseInt(line.substring(0, ma));
        int quantum = Integer.parseInt(line.substring(ma+1));
        
        ArrayList<String> lingerJob = new ArrayList<String>();
        ArrayList<Integer> lingerTime = new ArrayList<Integer>();
        
        for(int i=0;i<jobAmount;i++){
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        }
        
        
        
        int nowTime=0;
        
        while(lingerJob.size()!=0){
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int ma = line.indexOf(" ");
        int jobAmount = Integer.parseInt(line.substring(0, ma));
        int quantum = Integer.parseInt(line.substring(ma+1));
        
        ArrayList<String> lingerJob = new ArrayList<String>();
        ArrayList<Integer> lingerTime = new ArrayList<Integer>();
        
        for(int i=0;i<jobAmount;i++){
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        }
        
        
        
        int nowTime=0;
        
        while(lingerJob.size()!=0){
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int ma = line.indexOf(" ");
        int jobAmount = Integer.parseInt(line.substring(0, ma));
        int quantum = Integer.parseInt(line.substring(ma+1));
        
        ArrayList<String> lingerJob = new ArrayList<String>();
        ArrayList<Integer> lingerTime = new ArrayList<Integer>();
        
        for(int i=0;i<jobAmount;i++){
        	String line2 = sc.nextLine();
        	int ma2 = line2.indexOf(" ");
        	
        	lingerJob.add(line2.substring(0, ma2));
        	lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));
        }
        
        
        
        int nowTime=0;
        
        while(lingerJob.size()!=0){
        	
        	if(lingerTime.get(0)>quantum){
        		lingerJob.add(lingerJob.get(0));
        		lingerJob.remove(0);
        		lingerTime.add(lingerTime.get(0)-quantum);
        		lingerTime.remove(0);
        		nowTime+=quantum;  		
        	}else{
        		nowTime+=lingerTime.get(0);
        		System.out.println(lingerJob.get(0)+" "+nowTime);
        		lingerJob.remove(0);
        		lingerTime.remove(0);       		
        	}
        }
    }
}