import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> queue = new ArrayDeque<Process>();
        for(int i=0; i<n; i++) {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        }
        int pTime = 0;
        int b = 0;
        String[] result = new String[n];
        while(queue.size()>0) {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        }
        for(String s:result) {
            System.out.println(s);
        }
    }
}
class Process{
    String name;
    int time;
    Process(String name, int time) {
        this.name=name;
        this.time=time;
    }
}
 import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> queue = new ArrayDeque<Process>();
        for(int i=0; i<n; i++) {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        }
        int pTime = 0;
        int b = 0;
        String[] result = new String[n];
        while(queue.size()>0) {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        }
        for(String s:result) {
            System.out.println(s);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> queue = new ArrayDeque<Process>();
        for(int i=0; i<n; i++) {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        }
        int pTime = 0;
        int b = 0;
        String[] result = new String[n];
        while(queue.size()>0) {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        }
        for(String s:result) {
            System.out.println(s);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> queue = new ArrayDeque<Process>();
        for(int i=0; i<n; i++) {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        }
        int pTime = 0;
        int b = 0;
        String[] result = new String[n];
        while(queue.size()>0) {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        }
        for(String s:result) {
            System.out.println(s);
        }
    } 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 Queue<Process> queue = new ArrayDeque<Process>(); queue new ArrayDeque<Process>() for(int i=0; i<n; i++) {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        } {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        } Process p = new Process(sc.next(),sc.nextInt()); p new Process(sc.next(),sc.nextInt()) queue.add(p) queue.add queue p int pTime = 0; pTime 0 int b = 0; b 0 String[] result = new String[n]; result new String[n] n while(queue.size()>0) {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        } queue.size()>0 queue.size() queue.size queue 0 {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        } Process pro = queue.poll(); pro queue.poll() queue.poll queue if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            } pro.time>q pro.time pro pro.time q {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } pro.time -= q pro.time pro pro.time q queue.add(pro) queue.add queue pro pTime += q pTime q {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            } pTime += pro.time pTime pro.time pro pro.time result[b] = pro.name+" "+Integer.toString(pTime) result[b] result b pro.name+" "+Integer.toString(pTime) pro.name+" "+Integer.toString(pTime) pro.name pro pro.name " " Integer.toString(pTime) Integer.toString Integer pTime b++ b for(String s:result) {
            System.out.println(s);
        } String s result {
            System.out.println(s);
        } {
            System.out.println(s);
        } System.out.println(s) System.out.println System.out System System.out s String[] args args class Process{
    String name;
    int time;
    Process(String name, int time) {
        this.name=name;
        this.time=time;
    }
} Process String name; name int time; time 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();
        Queue<Process> queue = new ArrayDeque<Process>();
        for(int i=0; i<n; i++) {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        }
        int pTime = 0;
        int b = 0;
        String[] result = new String[n];
        while(queue.size()>0) {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        }
        for(String s:result) {
            System.out.println(s);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> queue = new ArrayDeque<Process>();
        for(int i=0; i<n; i++) {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        }
        int pTime = 0;
        int b = 0;
        String[] result = new String[n];
        while(queue.size()>0) {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        }
        for(String s:result) {
            System.out.println(s);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> queue = new ArrayDeque<Process>();
        for(int i=0; i<n; i++) {
            Process p = new Process(sc.next(),sc.nextInt());
            queue.add(p);
        }
        int pTime = 0;
        int b = 0;
        String[] result = new String[n];
        while(queue.size()>0) {
            Process pro = queue.poll();
            if(pro.time>q) {
                pro.time -= q;
                queue.add(pro);
                pTime += q;
            } else {
                pTime += pro.time;
                result[b] = pro.name+" "+Integer.toString(pTime);
                b++;
            }
        }
        for(String s:result) {
            System.out.println(s);
        }
    }
}
class Process{
    String name;
    int time;
    Process(String name, int time) {
        this.name=name;
        this.time=time;
    }
}

