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();
        ArrayDeque<Proc> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        }
        StringBuilder sb = new StringBuilder();
        int current = 0;
        while (queue.size() > 0) {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Proc {
        String name;
        int time;
        
        public Proc(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();
        ArrayDeque<Proc> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        }
        StringBuilder sb = new StringBuilder();
        int current = 0;
        while (queue.size() > 0) {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Proc {
        String name;
        int time;
        
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        ArrayDeque<Proc> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        }
        StringBuilder sb = new StringBuilder();
        int current = 0;
        while (queue.size() > 0) {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        }
        System.out.print(sb);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        ArrayDeque<Proc> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        }
        StringBuilder sb = new StringBuilder();
        int current = 0;
        while (queue.size() > 0) {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        }
        System.out.print(sb);
    } 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 ArrayDeque<Proc> queue = new ArrayDeque<>(); queue new ArrayDeque<>() for (int i = 0; i < n; i++) {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        } {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        } queue.add(new Proc(sc.next(), sc.nextInt())) queue.add queue new Proc(sc.next(), sc.nextInt()) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int current = 0; current 0 while (queue.size() > 0) {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        } queue.size() > 0 queue.size() queue.size queue 0 {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        } Proc p = queue.poll(); p queue.poll() queue.poll queue if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            } p.time > q p.time p p.time q {
                p.time -= q;
                queue.add(p);
                current += q;
            } p.time -= q p.time p p.time q queue.add(p) queue.add queue p current += q current q {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            } current += p.time current p.time p p.time sb.append(p.name).append(" ").append(current).append("\n") sb.append(p.name).append(" ").append(current).append sb.append(p.name).append(" ").append(current) sb.append(p.name).append(" ").append sb.append(p.name).append(" ") sb.append(p.name).append sb.append(p.name) sb.append sb p.name p p.name " " current "\n" System.out.print(sb) System.out.print System.out System System.out sb String[] args args static class Proc {
        String name;
        int time;
        
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
    } Proc String name; name int time; time public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        } Proc {
            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();
        ArrayDeque<Proc> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        }
        StringBuilder sb = new StringBuilder();
        int current = 0;
        while (queue.size() > 0) {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Proc {
        String name;
        int time;
        
        public Proc(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();
        ArrayDeque<Proc> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        }
        StringBuilder sb = new StringBuilder();
        int current = 0;
        while (queue.size() > 0) {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Proc {
        String name;
        int time;
        
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }
} 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();
        ArrayDeque<Proc> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Proc(sc.next(), sc.nextInt()));
        }
        StringBuilder sb = new StringBuilder();
        int current = 0;
        while (queue.size() > 0) {
            Proc p = queue.poll();
            if (p.time > q) {
                p.time -= q;
                queue.add(p);
                current += q;
            } else {
                current += p.time;
                sb.append(p.name).append(" ").append(current).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Proc {
        String name;
        int time;
        
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }
}
