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 process = 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<process;i++){
            String line2 = sc.nextLine();
            int ma2 =line2.indexOf(" ");
            lingerJob.add(line2.substring(0, ma2));
            lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));      	
        }

        int save=-1;
        int timeCount=0;
        
        while(lingerJob.size()!=0){
        	for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.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 process = 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<process;i++){
            String line2 = sc.nextLine();
            int ma2 =line2.indexOf(" ");
            lingerJob.add(line2.substring(0, ma2));
            lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));      	
        }

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

        int save=-1;
        int timeCount=0;
        
        while(lingerJob.size()!=0){
        	for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		}
        	}
        }
    } main {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int ma =line.indexOf(" ");
        int process = 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<process;i++){
            String line2 = sc.nextLine();
            int ma2 =line2.indexOf(" ");
            lingerJob.add(line2.substring(0, ma2));
            lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));      	
        }

        int save=-1;
        int timeCount=0;
        
        while(lingerJob.size()!=0){
        	for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.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 process = Integer.parseInt(line.substring(0, ma)); process 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<process;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<process i process 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 save=-1; save -1 1 int timeCount=0; timeCount 0 while(lingerJob.size()!=0){
        	for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		}
        	}
        } lingerJob.size()!=0 lingerJob.size() lingerJob.size lingerJob 0 {
        	for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		}
        	}
        } for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		}
        	} int i=0; int i=0; i 0 i<lingerJob.size() i lingerJob.size() lingerJob.size lingerJob i++ i++ i {
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		}
        	} {
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		}
        	} if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		} lingerTime.get(0)>quantum lingerTime.get(0) lingerTime.get lingerTime 0 quantum {
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		} 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 lingerJob.add(lingerJob.get(0)) lingerJob.add lingerJob lingerJob.get(0) lingerJob.get lingerJob 0 lingerJob.remove(0) lingerJob.remove lingerJob 0 timeCount=timeCount+quantum timeCount timeCount+quantum timeCount quantum {
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		} timeCount=timeCount+lingerTime.get(0) timeCount timeCount+lingerTime.get(0) timeCount lingerTime.get(0) lingerTime.get lingerTime 0 System.out.println(lingerJob.get(0)+" "+timeCount) System.out.println System.out System System.out lingerJob.get(0)+" "+timeCount lingerJob.get(0)+" "+timeCount lingerJob.get(0) lingerJob.get lingerJob 0 " " timeCount lingerTime.remove(0) lingerTime.remove lingerTime 0 lingerJob.remove(0) lingerJob.remove lingerJob 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 process = 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<process;i++){
            String line2 = sc.nextLine();
            int ma2 =line2.indexOf(" ");
            lingerJob.add(line2.substring(0, ma2));
            lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));      	
        }

        int save=-1;
        int timeCount=0;
        
        while(lingerJob.size()!=0){
        	for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.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 process = 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<process;i++){
            String line2 = sc.nextLine();
            int ma2 =line2.indexOf(" ");
            lingerJob.add(line2.substring(0, ma2));
            lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));      	
        }

        int save=-1;
        int timeCount=0;
        
        while(lingerJob.size()!=0){
        	for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.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 process = 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<process;i++){
            String line2 = sc.nextLine();
            int ma2 =line2.indexOf(" ");
            lingerJob.add(line2.substring(0, ma2));
            lingerTime.add(Integer.parseInt(line2.substring(ma2+1)));      	
        }

        int save=-1;
        int timeCount=0;
        
        while(lingerJob.size()!=0){
        	for(int i=0;i<lingerJob.size();i++){
        		if(lingerTime.get(0)>quantum){
        			lingerTime.add(lingerTime.get(0)-quantum);
        			lingerTime.remove(0);
        			lingerJob.add(lingerJob.get(0));
        			lingerJob.remove(0);
        			timeCount=timeCount+quantum;
        		}else{
        			timeCount=timeCount+lingerTime.get(0);
        			System.out.println(lingerJob.get(0)+" "+timeCount);
        			lingerTime.remove(0);
        			lingerJob.remove(0);
        		}
        	}
        }
    }   
}