import java.util.*;
 
class process {
 
    private String name;
    private int time;
     
    public process(String name,int time){
        this.name = name;
        this.time = time;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getName() {
        return name;
    }
 
    public void setTime(int time) {
        this.time = time;
    }
 
    public int getTime() {
        return time;
    }
}
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        ArrayList<process> ar = new ArrayList<process>();
        ArrayList<process> result = new ArrayList<process>();
         
        for (int i = 0; i < n; i++){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        }
         
        int LapsedTime = 0,i = 0;
        process p;
         
        while(true){
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        }
    }
} import java.util.*; util.* java class process {
 
    private String name;
    private int time;
     
    public process(String name,int time){
        this.name = name;
        this.time = time;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getName() {
        return name;
    }
 
    public void setTime(int time) {
        this.time = time;
    }
 
    public int getTime() {
        return time;
    }
} process private String name; name private int time; time public process(String name,int time){
        this.name = name;
        this.time = time;
    } process {
        this.name = name;
        this.time = time;
    } this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public void setName(String name) {
        this.name = name;
    } setName {
        this.name = name;
    } this.name = name this.name this this.name name String name name public String getName() {
        return name;
    } getName {
        return name;
    } return name; name public void setTime(int time) {
        this.time = time;
    } setTime {
        this.time = time;
    } this.time = time this.time this this.time time int time time public int getTime() {
        return time;
    } getTime {
        return time;
    } return time; time public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        ArrayList<process> ar = new ArrayList<process>();
        ArrayList<process> result = new ArrayList<process>();
         
        for (int i = 0; i < n; i++){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        }
         
        int LapsedTime = 0,i = 0;
        process p;
         
        while(true){
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        }
    }
} Main public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        ArrayList<process> ar = new ArrayList<process>();
        ArrayList<process> result = new ArrayList<process>();
         
        for (int i = 0; i < n; i++){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        }
         
        int LapsedTime = 0,i = 0;
        process p;
         
        while(true){
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        }
    } main {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        ArrayList<process> ar = new ArrayList<process>();
        ArrayList<process> result = new ArrayList<process>();
         
        for (int i = 0; i < n; i++){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        }
         
        int LapsedTime = 0,i = 0;
        process p;
         
        while(true){
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc ArrayList<process> ar = new ArrayList<process>(); ar new ArrayList<process>() ArrayList<process> result = new ArrayList<process>(); result new ArrayList<process>() for (int i = 0; i < n; i++){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        } {
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        } ar.add(new process(sc.next(),Integer.parseInt(sc.next()))) ar.add ar new process(sc.next(),Integer.parseInt(sc.next())) int LapsedTime = 0 LapsedTime 0 i = 0; i 0 process p; p while(true){
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        } true {
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        } if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            } i < n i n {
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                } (p = ar.get(i)).getTime() - q <= 0 (p = ar.get(i)).getTime() - q (p = ar.get(i)).getTime() (p = ar.get(i)).getTime (p = ar.get(i)) p ar.get(i) ar.get ar i q 0 {
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } LapsedTime += p.getTime() LapsedTime p.getTime() p.getTime p result.add(new process(p.getName(),LapsedTime)) result.add result new process(p.getName(),LapsedTime) ar.remove(i) ar.remove ar i n-- n {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                } LapsedTime += q LapsedTime q p.setTime(p.getTime() - q) p.setTime p p.getTime() - q p.getTime() p.getTime p q i++ i {
                i = 0;
            } i = 0 i 0 if (n == 0){
                break;
            } n == 0 n 0 {
                break;
            } break; for(process r:result) {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        } process r result {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        } {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        } System.out.println(r.getName() + " " + String.valueOf(r.getTime())) System.out.println System.out System System.out r.getName() + " " + String.valueOf(r.getTime()) r.getName() + " " + String.valueOf(r.getTime()) r.getName() r.getName r " " String.valueOf(r.getTime()) String.valueOf String r.getTime() r.getTime r String[] args args public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        ArrayList<process> ar = new ArrayList<process>();
        ArrayList<process> result = new ArrayList<process>();
         
        for (int i = 0; i < n; i++){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        }
         
        int LapsedTime = 0,i = 0;
        process p;
         
        while(true){
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        }
    }
} public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        ArrayList<process> ar = new ArrayList<process>();
        ArrayList<process> result = new ArrayList<process>();
         
        for (int i = 0; i < n; i++){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        }
         
        int LapsedTime = 0,i = 0;
        process p;
         
        while(true){
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        }
    }
} Main
import java.util.*;
 
class process {
 
    private String name;
    private int time;
     
    public process(String name,int time){
        this.name = name;
        this.time = time;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getName() {
        return name;
    }
 
    public void setTime(int time) {
        this.time = time;
    }
 
    public int getTime() {
        return time;
    }
}
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        ArrayList<process> ar = new ArrayList<process>();
        ArrayList<process> result = new ArrayList<process>();
         
        for (int i = 0; i < n; i++){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        }
         
        int LapsedTime = 0,i = 0;
        process p;
         
        while(true){
            if(i < n){
                if((p = ar.get(i)).getTime() - q <= 0){
                    LapsedTime += p.getTime();
                    result.add(new process(p.getName(),LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.setTime(p.getTime() - q);
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.getName() + " " + String.valueOf(r.getTime()));
        }
    }
}