import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int quantam=scan.nextInt();
        int erapsedTime=0;
        ArrayList<String> pname=new ArrayList<String>();
        ArrayList<Integer> ptime=new ArrayList<Integer>();
        
        for(int i=0; i<n; i++){
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        }
        //System.out.println(pname+":"+ptime);
        
        while(ptime.size()!=0){
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int quantam=scan.nextInt();
        int erapsedTime=0;
        ArrayList<String> pname=new ArrayList<String>();
        ArrayList<Integer> ptime=new ArrayList<Integer>();
        
        for(int i=0; i<n; i++){
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        }
        //System.out.println(pname+":"+ptime);
        
        while(ptime.size()!=0){
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        }
    }
} Main public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int quantam=scan.nextInt();
        int erapsedTime=0;
        ArrayList<String> pname=new ArrayList<String>();
        ArrayList<Integer> ptime=new ArrayList<Integer>();
        
        for(int i=0; i<n; i++){
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        }
        //System.out.println(pname+":"+ptime);
        
        while(ptime.size()!=0){
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        }
    } main {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int quantam=scan.nextInt();
        int erapsedTime=0;
        ArrayList<String> pname=new ArrayList<String>();
        ArrayList<Integer> ptime=new ArrayList<Integer>();
        
        for(int i=0; i<n; i++){
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        }
        //System.out.println(pname+":"+ptime);
        
        while(ptime.size()!=0){
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        }
    } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int quantam=scan.nextInt(); quantam scan.nextInt() scan.nextInt scan int erapsedTime=0; erapsedTime 0 ArrayList<String> pname=new ArrayList<String>(); pname new ArrayList<String>() ArrayList<Integer> ptime=new ArrayList<Integer>(); ptime new ArrayList<Integer>() for(int i=0; i<n; i++){
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        } {
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        } pname.add(scan.next()) pname.add pname scan.next() scan.next scan ptime.add(scan.nextInt()) ptime.add ptime scan.nextInt() scan.nextInt scan while(ptime.size()!=0){
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        } ptime.size()!=0 ptime.size() ptime.size ptime 0 {
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        } if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            } ptime.get(0)<=quantam ptime.get(0) ptime.get ptime 0 quantam {
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            } erapsedTime+=ptime.remove(0) erapsedTime ptime.remove(0) ptime.remove ptime 0 System.out.println(pname.remove(0)+" "+erapsedTime) System.out.println System.out System System.out pname.remove(0)+" "+erapsedTime pname.remove(0)+" "+erapsedTime pname.remove(0) pname.remove pname 0 " " erapsedTime {
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            } ptime.add(ptime.remove(0)-quantam) ptime.add ptime ptime.remove(0)-quantam ptime.remove(0) ptime.remove ptime 0 quantam pname.add(pname.remove(0)) pname.add pname pname.remove(0) pname.remove pname 0 erapsedTime+=quantam erapsedTime quantam String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int quantam=scan.nextInt();
        int erapsedTime=0;
        ArrayList<String> pname=new ArrayList<String>();
        ArrayList<Integer> ptime=new ArrayList<Integer>();
        
        for(int i=0; i<n; i++){
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        }
        //System.out.println(pname+":"+ptime);
        
        while(ptime.size()!=0){
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        }
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int quantam=scan.nextInt();
        int erapsedTime=0;
        ArrayList<String> pname=new ArrayList<String>();
        ArrayList<Integer> ptime=new ArrayList<Integer>();
        
        for(int i=0; i<n; i++){
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        }
        //System.out.println(pname+":"+ptime);
        
        while(ptime.size()!=0){
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        }
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int quantam=scan.nextInt();
        int erapsedTime=0;
        ArrayList<String> pname=new ArrayList<String>();
        ArrayList<Integer> ptime=new ArrayList<Integer>();
        
        for(int i=0; i<n; i++){
            pname.add(scan.next());
            ptime.add(scan.nextInt());
        }
        //System.out.println(pname+":"+ptime);
        
        while(ptime.size()!=0){
            if(ptime.get(0)<=quantam){
                erapsedTime+=ptime.remove(0);
                System.out.println(pname.remove(0)+" "+erapsedTime);
            }
            else{
                ptime.add(ptime.remove(0)-quantam);
                pname.add(pname.remove(0));
                erapsedTime+=quantam;
            }
        }
    }
}
