import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        Queue queue = new Queue();
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        }
        int t = 0;
        while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        }
    }

    private static class Process {
        private String name;
        private int time;

        private Process(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }

    private static class Queue {
        private static class Node {
            private Process process;
            private Node next;
            private Node prev;

            private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            }
        }

        private Node first;
        private Node last;

        private void enqueue(Process process) {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        }

        private Process dequeue() {
            Process process = first.process;
            first = first.prev;
            return process;
        }

        private boolean hasNode() {
            return first != null;
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        Queue queue = new Queue();
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        }
        int t = 0;
        while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        }
    }

    private static class Process {
        private String name;
        private int time;

        private Process(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }

    private static class Queue {
        private static class Node {
            private Process process;
            private Node next;
            private Node prev;

            private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            }
        }

        private Node first;
        private Node last;

        private void enqueue(Process process) {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        }

        private Process dequeue() {
            Process process = first.process;
            first = first.prev;
            return process;
        }

        private boolean hasNode() {
            return first != null;
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        Queue queue = new Queue();
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        }
        int t = 0;
        while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        Queue queue = new Queue();
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        }
        int t = 0;
        while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int q = scanner.nextInt(); q scanner.nextInt() scanner.nextInt scanner Queue queue = new Queue(); queue new Queue() for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        } {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        } queue.enqueue(new Process(scanner.next(), scanner.nextInt())) queue.enqueue queue new Process(scanner.next(), scanner.nextInt()) int t = 0; t 0 while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        } queue.hasNode() queue.hasNode queue {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        } Process process = queue.dequeue(); process queue.dequeue() queue.dequeue queue t += Math.min(process.time, q) t Math.min(process.time, q) Math.min Math process.time process process.time q if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            } process.time <= q process.time process process.time q {
                System.out.println(process.name + " " + String.valueOf(t));
            } System.out.println(process.name + " " + String.valueOf(t)) System.out.println System.out System System.out process.name + " " + String.valueOf(t) process.name + " " + String.valueOf(t) process.name process process.name " " String.valueOf(t) String.valueOf String t {
                process.time -= q;
                queue.enqueue(process);
            } process.time -= q process.time process process.time q queue.enqueue(process) queue.enqueue queue process String[] args args private static class Process {
        private String name;
        private int time;

        private Process(String name, int time) {
            this.name = name;
            this.time = time;
        }
    } Process private String name; name private int time; time private 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 private static class Queue {
        private static class Node {
            private Process process;
            private Node next;
            private Node prev;

            private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            }
        }

        private Node first;
        private Node last;

        private void enqueue(Process process) {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        }

        private Process dequeue() {
            Process process = first.process;
            first = first.prev;
            return process;
        }

        private boolean hasNode() {
            return first != null;
        }
    } Queue private Node first; first private Node last; last private void enqueue(Process process) {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        } enqueue {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        } last = new Node(process, last) last new Node(process, last) if (last.next != null) {
                last.next.prev = last;
            } last.next != null last.next last last.next null {
                last.next.prev = last;
            } last.next.prev = last last.next.prev last.next last last.next last.next.prev last if (first == null) {
                first = last;
            } first == null first null {
                first = last;
            } first = last first last Process process process private Process dequeue() {
            Process process = first.process;
            first = first.prev;
            return process;
        } dequeue {
            Process process = first.process;
            first = first.prev;
            return process;
        } Process process = first.process; process first.process first first.process first = first.prev first first.prev first first.prev return process; process private boolean hasNode() {
            return first != null;
        } hasNode {
            return first != null;
        } return first != null; first != null first null private static class Node {
            private Process process;
            private Node next;
            private Node prev;

            private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            }
        } Node private Process process; process private Node next; next private Node prev; prev private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            } Node {
                this.process = process;
                this.next = next;
            } this.process = process this.process this this.process process this.next = next this.next this this.next next Process process process Node next next public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        Queue queue = new Queue();
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        }
        int t = 0;
        while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        }
    }

    private static class Process {
        private String name;
        private int time;

        private Process(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }

    private static class Queue {
        private static class Node {
            private Process process;
            private Node next;
            private Node prev;

            private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            }
        }

        private Node first;
        private Node last;

        private void enqueue(Process process) {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        }

        private Process dequeue() {
            Process process = first.process;
            first = first.prev;
            return process;
        }

        private boolean hasNode() {
            return first != null;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        Queue queue = new Queue();
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        }
        int t = 0;
        while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        }
    }

    private static class Process {
        private String name;
        private int time;

        private Process(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }

    private static class Queue {
        private static class Node {
            private Process process;
            private Node next;
            private Node prev;

            private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            }
        }

        private Node first;
        private Node last;

        private void enqueue(Process process) {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        }

        private Process dequeue() {
            Process process = first.process;
            first = first.prev;
            return process;
        }

        private boolean hasNode() {
            return first != null;
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        Queue queue = new Queue();
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        }
        int t = 0;
        while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        }
    }

    private static class Process {
        private String name;
        private int time;

        private Process(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }

    private static class Queue {
        private static class Node {
            private Process process;
            private Node next;
            private Node prev;

            private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            }
        }

        private Node first;
        private Node last;

        private void enqueue(Process process) {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        }

        private Process dequeue() {
            Process process = first.process;
            first = first.prev;
            return process;
        }

        private boolean hasNode() {
            return first != null;
        }
    }
}