
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static class Proc {
        public String name;
        public int time;

        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }

        public int run(int quantum) {
            if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            }
        }

        public boolean isFinished() {
            return time == 0;
        }
    }

    static class Queue {
        Proc[] elements;
        int head = 0;
        int tail = 0;
        int count = 0;
        
        public Queue(int max) {
            elements = new Proc[max];
            head = 0;
            tail = 0;
            count = 0;
        }

        public boolean enqueue(Proc t) {
            if (isFull()) {
                return false;
            }
            elements[head++] = t;
            count++;
            if (head >= elements.length) {
                head = 0;
            }
            return true;
        }
        
        public Proc dequeue() {
            Proc elem = null;
            if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            }

            return elem;
        }

        public boolean isEmpty() {
            return count == 0;
        }
        
        public boolean isFull() {
            return count == elements.length;
        }
    }

    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] nAndq = r.readLine().split(" ");
        int n = Integer.parseInt(nAndq[0]);
        int q = Integer.parseInt(nAndq[1]);
        Queue queue = new Queue(n);
        
        for (int i = 0;i < n;i++) {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        }

        int clock = 0;
        while (!queue.isEmpty()) {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    static class Proc {
        public String name;
        public int time;

        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }

        public int run(int quantum) {
            if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            }
        }

        public boolean isFinished() {
            return time == 0;
        }
    }

    static class Queue {
        Proc[] elements;
        int head = 0;
        int tail = 0;
        int count = 0;
        
        public Queue(int max) {
            elements = new Proc[max];
            head = 0;
            tail = 0;
            count = 0;
        }

        public boolean enqueue(Proc t) {
            if (isFull()) {
                return false;
            }
            elements[head++] = t;
            count++;
            if (head >= elements.length) {
                head = 0;
            }
            return true;
        }
        
        public Proc dequeue() {
            Proc elem = null;
            if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            }

            return elem;
        }

        public boolean isEmpty() {
            return count == 0;
        }
        
        public boolean isFull() {
            return count == elements.length;
        }
    }

    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] nAndq = r.readLine().split(" ");
        int n = Integer.parseInt(nAndq[0]);
        int q = Integer.parseInt(nAndq[1]);
        Queue queue = new Queue(n);
        
        for (int i = 0;i < n;i++) {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        }

        int clock = 0;
        while (!queue.isEmpty()) {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] nAndq = r.readLine().split(" ");
        int n = Integer.parseInt(nAndq[0]);
        int q = Integer.parseInt(nAndq[1]);
        Queue queue = new Queue(n);
        
        for (int i = 0;i < n;i++) {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        }

        int clock = 0;
        while (!queue.isEmpty()) {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        }
    } main {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] nAndq = r.readLine().split(" ");
        int n = Integer.parseInt(nAndq[0]);
        int q = Integer.parseInt(nAndq[1]);
        Queue queue = new Queue(n);
        
        for (int i = 0;i < n;i++) {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        }

        int clock = 0;
        while (!queue.isEmpty()) {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        }
    } BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); r new BufferedReader(new InputStreamReader(System.in)) String[] nAndq = r.readLine().split(" "); nAndq r.readLine().split(" ") r.readLine().split r.readLine() r.readLine r " " int n = Integer.parseInt(nAndq[0]); n Integer.parseInt(nAndq[0]) Integer.parseInt Integer nAndq[0] nAndq 0 int q = Integer.parseInt(nAndq[1]); q Integer.parseInt(nAndq[1]) Integer.parseInt Integer nAndq[1] nAndq 1 Queue queue = new Queue(n); queue new Queue(n) for (int i = 0;i < n;i++) {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        } {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        } String[] elems = r.readLine().split(" "); elems r.readLine().split(" ") r.readLine().split r.readLine() r.readLine r " " if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            } !queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1]))) queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1]))) queue.enqueue queue new Proc(elems[0], Integer.parseInt(elems[1])) {
                System.err.println("Failed enqueue.");
            } System.err.println("Failed enqueue.") System.err.println System.err System System.err "Failed enqueue." int clock = 0; clock 0 while (!queue.isEmpty()) {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        } Proc p = queue.dequeue(); p queue.dequeue() queue.dequeue queue clock += p.run(q) clock p.run(q) p.run p q if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            } p.isFinished() p.isFinished p {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } System.out.println(p.name + " " + clock) System.out.println System.out System System.out p.name + " " + clock p.name + " " + clock p.name p p.name " " clock if (queue.isEmpty()) {
                    break;
                } queue.isEmpty() queue.isEmpty queue {
                    break;
                } break; {
                queue.enqueue(p);
            } queue.enqueue(p) queue.enqueue queue p String[] args args static class Proc {
        public String name;
        public int time;

        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }

        public int run(int quantum) {
            if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            }
        }

        public boolean isFinished() {
            return time == 0;
        }
    } Proc public String name; name public 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 int run(int quantum) {
            if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            }
        } run {
            if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            }
        } if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            } time > quantum time quantum {
                time -= quantum;
                return quantum;
            } time -= quantum time quantum return quantum; quantum {
                quantum = time;
                time = 0;
                return quantum;
            } quantum = time quantum time time = 0 time 0 return quantum; quantum int quantum quantum public boolean isFinished() {
            return time == 0;
        } isFinished {
            return time == 0;
        } return time == 0; time == 0 time 0 static class Queue {
        Proc[] elements;
        int head = 0;
        int tail = 0;
        int count = 0;
        
        public Queue(int max) {
            elements = new Proc[max];
            head = 0;
            tail = 0;
            count = 0;
        }

        public boolean enqueue(Proc t) {
            if (isFull()) {
                return false;
            }
            elements[head++] = t;
            count++;
            if (head >= elements.length) {
                head = 0;
            }
            return true;
        }
        
        public Proc dequeue() {
            Proc elem = null;
            if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            }

            return elem;
        }

        public boolean isEmpty() {
            return count == 0;
        }
        
        public boolean isFull() {
            return count == elements.length;
        }
    } Queue Proc[] elements; elements int head = 0; head 0 int tail = 0; tail 0 int count = 0; count 0 public Queue(int max) {
            elements = new Proc[max];
            head = 0;
            tail = 0;
            count = 0;
        } Queue {
            elements = new Proc[max];
            head = 0;
            tail = 0;
            count = 0;
        } elements = new Proc[max] elements new Proc[max] max head = 0 head 0 tail = 0 tail 0 count = 0 count 0 int max max public boolean enqueue(Proc t) {
            if (isFull()) {
                return false;
            }
            elements[head++] = t;
            count++;
            if (head >= elements.length) {
                head = 0;
            }
            return true;
        } enqueue {
            if (isFull()) {
                return false;
            }
            elements[head++] = t;
            count++;
            if (head >= elements.length) {
                head = 0;
            }
            return true;
        } if (isFull()) {
                return false;
            } isFull() isFull {
                return false;
            } return false; false elements[head++] = t elements[head++] elements head++ head t count++ count if (head >= elements.length) {
                head = 0;
            } head >= elements.length head elements.length elements elements.length {
                head = 0;
            } head = 0 head 0 return true; true Proc t t public Proc dequeue() {
            Proc elem = null;
            if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            }

            return elem;
        } dequeue {
            Proc elem = null;
            if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            }

            return elem;
        } Proc elem = null; elem null if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            } !isEmpty() isEmpty() isEmpty {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            } elem = elements[tail++] elem elements[tail++] elements tail++ tail count-- count if (tail >= elements.length) {
                    tail = 0;
                } tail >= elements.length tail elements.length elements elements.length {
                    tail = 0;
                } tail = 0 tail 0 return elem; elem public boolean isEmpty() {
            return count == 0;
        } isEmpty {
            return count == 0;
        } return count == 0; count == 0 count 0 public boolean isFull() {
            return count == elements.length;
        } isFull {
            return count == elements.length;
        } return count == elements.length; count == elements.length count elements.length elements elements.length public class Main {
    static class Proc {
        public String name;
        public int time;

        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }

        public int run(int quantum) {
            if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            }
        }

        public boolean isFinished() {
            return time == 0;
        }
    }

    static class Queue {
        Proc[] elements;
        int head = 0;
        int tail = 0;
        int count = 0;
        
        public Queue(int max) {
            elements = new Proc[max];
            head = 0;
            tail = 0;
            count = 0;
        }

        public boolean enqueue(Proc t) {
            if (isFull()) {
                return false;
            }
            elements[head++] = t;
            count++;
            if (head >= elements.length) {
                head = 0;
            }
            return true;
        }
        
        public Proc dequeue() {
            Proc elem = null;
            if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            }

            return elem;
        }

        public boolean isEmpty() {
            return count == 0;
        }
        
        public boolean isFull() {
            return count == elements.length;
        }
    }

    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] nAndq = r.readLine().split(" ");
        int n = Integer.parseInt(nAndq[0]);
        int q = Integer.parseInt(nAndq[1]);
        Queue queue = new Queue(n);
        
        for (int i = 0;i < n;i++) {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        }

        int clock = 0;
        while (!queue.isEmpty()) {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        }
    }
} public class Main {
    static class Proc {
        public String name;
        public int time;

        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }

        public int run(int quantum) {
            if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            }
        }

        public boolean isFinished() {
            return time == 0;
        }
    }

    static class Queue {
        Proc[] elements;
        int head = 0;
        int tail = 0;
        int count = 0;
        
        public Queue(int max) {
            elements = new Proc[max];
            head = 0;
            tail = 0;
            count = 0;
        }

        public boolean enqueue(Proc t) {
            if (isFull()) {
                return false;
            }
            elements[head++] = t;
            count++;
            if (head >= elements.length) {
                head = 0;
            }
            return true;
        }
        
        public Proc dequeue() {
            Proc elem = null;
            if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            }

            return elem;
        }

        public boolean isEmpty() {
            return count == 0;
        }
        
        public boolean isFull() {
            return count == elements.length;
        }
    }

    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] nAndq = r.readLine().split(" ");
        int n = Integer.parseInt(nAndq[0]);
        int q = Integer.parseInt(nAndq[1]);
        Queue queue = new Queue(n);
        
        for (int i = 0;i < n;i++) {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        }

        int clock = 0;
        while (!queue.isEmpty()) {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        }
    }
} Main

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static class Proc {
        public String name;
        public int time;

        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }

        public int run(int quantum) {
            if (time > quantum) {
                time -= quantum;
                return quantum;
            } else {
                quantum = time;
                time = 0;
                return quantum;
            }
        }

        public boolean isFinished() {
            return time == 0;
        }
    }

    static class Queue {
        Proc[] elements;
        int head = 0;
        int tail = 0;
        int count = 0;
        
        public Queue(int max) {
            elements = new Proc[max];
            head = 0;
            tail = 0;
            count = 0;
        }

        public boolean enqueue(Proc t) {
            if (isFull()) {
                return false;
            }
            elements[head++] = t;
            count++;
            if (head >= elements.length) {
                head = 0;
            }
            return true;
        }
        
        public Proc dequeue() {
            Proc elem = null;
            if (!isEmpty()) {
                elem = elements[tail++];
                count--;
                if (tail >= elements.length) {
                    tail = 0;
                }
            }

            return elem;
        }

        public boolean isEmpty() {
            return count == 0;
        }
        
        public boolean isFull() {
            return count == elements.length;
        }
    }

    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] nAndq = r.readLine().split(" ");
        int n = Integer.parseInt(nAndq[0]);
        int q = Integer.parseInt(nAndq[1]);
        Queue queue = new Queue(n);
        
        for (int i = 0;i < n;i++) {
            String[] elems = r.readLine().split(" ");
            if (!queue.enqueue(new Proc(elems[0], Integer.parseInt(elems[1])))) {
                System.err.println("Failed enqueue.");
            }
        }

        int clock = 0;
        while (!queue.isEmpty()) {
            Proc p = queue.dequeue();
            clock += p.run(q);
            if (p.isFinished()) {
                System.out.println(p.name + " " + clock);
                if (queue.isEmpty()) {
                    break;
                }
            } else {
                queue.enqueue(p);
            }
        }
    }
}