import java.util.*;
 
class process {
    public String name;
    public int time;
     
    public process(String name,int time){
        this.name = name;
        this.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)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.name + " " + String.valueOf(r.time));
        }
    }
} import java.util.*; util.* java class process {
    public String name;
    public int time;
     
    public process(String name,int time){
        this.name = name;
        this.time = time;
    }
} process public String name; name public 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 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)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.name + " " + String.valueOf(r.time));
        }
    }
} 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)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.name + " " + String.valueOf(r.time));
        }
    } 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)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.name + " " + String.valueOf(r.time));
        }
    } 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)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        } true {
            if(i < n){
                if((p = ar.get(i)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        } if(i < n){
                if((p = ar.get(i)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            } i < n i n {
                if((p = ar.get(i)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } if((p = ar.get(i)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                } (p = ar.get(i)).time - q <= 0 (p = ar.get(i)).time - q (p = ar.get(i)).time (p = ar.get(i)) p ar.get(i) ar.get ar i (p = ar.get(i)).time q 0 {
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } LapsedTime += p.time LapsedTime p.time p p.time result.add(new process(p.name,LapsedTime)) result.add result new process(p.name,LapsedTime) ar.remove(i) ar.remove ar i n-- n {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                } LapsedTime += q LapsedTime q p.time = p.time - q p.time p p.time p.time - q p.time p p.time 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.name + " " + String.valueOf(r.time));
        } process r result {
            System.out.println(r.name + " " + String.valueOf(r.time));
        } {
            System.out.println(r.name + " " + String.valueOf(r.time));
        } System.out.println(r.name + " " + String.valueOf(r.time)) System.out.println System.out System System.out r.name + " " + String.valueOf(r.time) r.name + " " + String.valueOf(r.time) r.name r r.name " " String.valueOf(r.time) String.valueOf String r.time r r.time 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)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.name + " " + String.valueOf(r.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)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.name + " " + String.valueOf(r.time));
        }
    }
} Main
import java.util.*;
 
class process {
    public String name;
    public int time;
     
    public process(String name,int time){
        this.name = name;
        this.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)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.name + " " + String.valueOf(r.time));
        }
    }
}