import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuQueue solver = new AizuQueue();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuQueue {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        }

        static class Queue {
            private Node head;
            private Node tail;

            public Queue() {
                head = tail = null;
            }

            public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            }

            public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            }

            public boolean isEmpty() {
                return head == null;
            }

            static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            }

        }

        static class Pair {
            String id;
            int t;

            public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            }

        }

    }
}

 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuQueue solver = new AizuQueue();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuQueue {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        }

        static class Queue {
            private Node head;
            private Node tail;

            public Queue() {
                head = tail = null;
            }

            public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            }

            public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            }

            public boolean isEmpty() {
                return head == null;
            }

            static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            }

        }

        static class Pair {
            String id;
            int t;

            public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            }

        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuQueue solver = new AizuQueue();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuQueue solver = new AizuQueue();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) AizuQueue solver = new AizuQueue(); solver new AizuQueue() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class AizuQueue {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        }

        static class Queue {
            private Node head;
            private Node tail;

            public Queue() {
                head = tail = null;
            }

            public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            }

            public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            }

            public boolean isEmpty() {
                return head == null;
            }

            static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            }

        }

        static class Pair {
            String id;
            int t;

            public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            }

        }

    } AizuQueue public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        } solve {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        } final int n = in.nextInt(); n in.nextInt() in.nextInt in final int q = in.nextInt(); q in.nextInt() in.nextInt in Queue queue = new Queue(); queue new Queue() for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            } {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            } final String id = in.next(); id in.next() in.next in final int t = in.nextInt(); t in.nextInt() in.nextInt in queue.enqueue(new Pair(id, t)) queue.enqueue queue new Pair(id, t) long curr = 0L; curr 0L while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            } Pair p = queue.dequeue(); p queue.dequeue() queue.dequeue queue if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                } p.t > q p.t p p.t q {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } curr += q curr q p.t -= q p.t p p.t q queue.enqueue(p) queue.enqueue queue p {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                } curr += p.t curr p.t p p.t out.printf("%s %d\n", p.id, curr) out.printf out "%s %d\n" p.id p p.id curr int testNumber testNumber Scanner in in PrintWriter out out static class Queue {
            private Node head;
            private Node tail;

            public Queue() {
                head = tail = null;
            }

            public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            }

            public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            }

            public boolean isEmpty() {
                return head == null;
            }

            static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            }

        } Queue private Node head; head private Node tail; tail public Queue() {
                head = tail = null;
            } Queue {
                head = tail = null;
            } head = tail = null head tail = null tail null public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            } enqueue {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            } Node n = new Node(p, null, null); n new Node(p, null, null) if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                } head == null head null {
                    head = tail = n;
                } head = tail = n head tail = n tail n {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                } tail.next = n tail.next tail tail.next n n.prev = tail n.prev n n.prev tail tail = n tail n final Pair p p public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            } dequeue {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            } if (head == null) {
                    throw new IllegalStateException("empty queue");
                } head == null head null {
                    throw new IllegalStateException("empty queue");
                } throw new IllegalStateException("empty queue"); new IllegalStateException("empty queue") final Pair p = head.key; p head.key head head.key head = head.next head head.next head head.next if (head == null) {
                    tail = null;
                } head == null head null {
                    tail = null;
                } tail = null tail null return p; p public boolean isEmpty() {
                return head == null;
            } isEmpty {
                return head == null;
            } return head == null; head == null head null static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            } Node Pair key; key Node next; next Node prev; prev public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                } Node {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                } this.key = key this.key this this.key key this.prev = prev this.prev this this.prev prev this.next = next this.next this this.next next final Pair key key final Node prev prev final Node next next static class Pair {
            String id;
            int t;

            public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            }

        } Pair String id; id int t; t public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            } Pair {
                this.id = id;
                this.t = t;
            } this.id = id this.id this this.id id this.t = t this.t this this.t t final String id id final int t t public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuQueue solver = new AizuQueue();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuQueue {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        }

        static class Queue {
            private Node head;
            private Node tail;

            public Queue() {
                head = tail = null;
            }

            public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            }

            public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            }

            public boolean isEmpty() {
                return head == null;
            }

            static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            }

        }

        static class Pair {
            String id;
            int t;

            public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            }

        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuQueue solver = new AizuQueue();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuQueue {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        }

        static class Queue {
            private Node head;
            private Node tail;

            public Queue() {
                head = tail = null;
            }

            public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            }

            public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            }

            public boolean isEmpty() {
                return head == null;
            }

            static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            }

        }

        static class Pair {
            String id;
            int t;

            public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            }

        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuQueue solver = new AizuQueue();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuQueue {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        }

        static class Queue {
            private Node head;
            private Node tail;

            public Queue() {
                head = tail = null;
            }

            public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            }

            public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            }

            public boolean isEmpty() {
                return head == null;
            }

            static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            }

        }

        static class Pair {
            String id;
            int t;

            public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            }

        }

    }
}


