import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.nextInt();

        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        }

        int time = 0;
        while (!queue.isEmpty()) {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        }

        pw.flush();
    }

    static class Process {
        String name;
        int time;

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

    static class Queue {
        Process[] Q;
        int lastIndex;
        int head;
        int tail;

        Queue(int n) {
            Q = new Process[n + 1];
            lastIndex = n;
            head = 0;
            tail = 0;
        }

        void enqueue(Process x) {
            Q[tail++] = new Process(x.name, x.time);
            if (tail > lastIndex)
                tail = 0;
        }

        Process dequeue() {
            Process x = Q[head++];
            if (head > lastIndex)
                head = 0;
            return x;
        }

        boolean isEmpty() {
            return head == tail ? true : false;
        }
    }
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.nextInt();

        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        }

        int time = 0;
        while (!queue.isEmpty()) {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        }

        pw.flush();
    }

    static class Process {
        String name;
        int time;

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

    static class Queue {
        Process[] Q;
        int lastIndex;
        int head;
        int tail;

        Queue(int n) {
            Q = new Process[n + 1];
            lastIndex = n;
            head = 0;
            tail = 0;
        }

        void enqueue(Process x) {
            Q[tail++] = new Process(x.name, x.time);
            if (tail > lastIndex)
                tail = 0;
        }

        Process dequeue() {
            Process x = Q[head++];
            if (head > lastIndex)
                head = 0;
            return x;
        }

        boolean isEmpty() {
            return head == tail ? true : false;
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.nextInt();

        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        }

        int time = 0;
        while (!queue.isEmpty()) {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        }

        pw.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.nextInt();

        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        }

        int time = 0;
        while (!queue.isEmpty()) {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        }

        pw.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter pw = new PrintWriter(System.out); pw new PrintWriter(System.out) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Queue queue = new Queue(n); queue new Queue(n) for (int i = 0; i < n; i++) {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        } {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        } String name = sc.next(); name sc.next() sc.next sc int time = sc.nextInt(); time sc.nextInt() sc.nextInt sc Process x = new Process(name, time); x new Process(name, time) queue.enqueue(x) queue.enqueue queue x int time = 0; time 0 while (!queue.isEmpty()) {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        } Process x = queue.dequeue(); x queue.dequeue() queue.dequeue queue if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            } x.time - q <= 0 x.time - q x.time x x.time q 0 {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } time += x.time time x.time x x.time pw.print(x.name + " ") pw.print pw x.name + " " x.name x x.name " " pw.println(time) pw.println pw time {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            } time += q time q x.time -= q x.time x x.time q queue.enqueue(x) queue.enqueue queue x pw.flush() pw.flush pw String[] args args static class Process {
        String name;
        int time;

        Process(String name, int time) {
            this.name = new String(name);
            this.time = time;
        }
    } Process String name; name int time; time Process(String name, int time) {
            this.name = new String(name);
            this.time = time;
        } Process {
            this.name = new String(name);
            this.time = time;
        } this.name = new String(name) this.name this this.name new String(name) this.time = time this.time this this.time time String name name int time time static class Queue {
        Process[] Q;
        int lastIndex;
        int head;
        int tail;

        Queue(int n) {
            Q = new Process[n + 1];
            lastIndex = n;
            head = 0;
            tail = 0;
        }

        void enqueue(Process x) {
            Q[tail++] = new Process(x.name, x.time);
            if (tail > lastIndex)
                tail = 0;
        }

        Process dequeue() {
            Process x = Q[head++];
            if (head > lastIndex)
                head = 0;
            return x;
        }

        boolean isEmpty() {
            return head == tail ? true : false;
        }
    } Queue Process[] Q; Q int lastIndex; lastIndex int head; head int tail; tail Queue(int n) {
            Q = new Process[n + 1];
            lastIndex = n;
            head = 0;
            tail = 0;
        } Queue {
            Q = new Process[n + 1];
            lastIndex = n;
            head = 0;
            tail = 0;
        } Q = new Process[n + 1] Q new Process[n + 1] n + 1 n 1 lastIndex = n lastIndex n head = 0 head 0 tail = 0 tail 0 int n n void enqueue(Process x) {
            Q[tail++] = new Process(x.name, x.time);
            if (tail > lastIndex)
                tail = 0;
        } enqueue {
            Q[tail++] = new Process(x.name, x.time);
            if (tail > lastIndex)
                tail = 0;
        } Q[tail++] = new Process(x.name, x.time) Q[tail++] Q tail++ tail new Process(x.name, x.time) if (tail > lastIndex)
                tail = 0; tail > lastIndex tail lastIndex tail = 0 tail 0 Process x x Process dequeue() {
            Process x = Q[head++];
            if (head > lastIndex)
                head = 0;
            return x;
        } dequeue {
            Process x = Q[head++];
            if (head > lastIndex)
                head = 0;
            return x;
        } Process x = Q[head++]; x Q[head++] Q head++ head if (head > lastIndex)
                head = 0; head > lastIndex head lastIndex head = 0 head 0 return x; x boolean isEmpty() {
            return head == tail ? true : false;
        } isEmpty {
            return head == tail ? true : false;
        } return head == tail ? true : false; head == tail ? true : false head == tail head tail true false public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.nextInt();

        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        }

        int time = 0;
        while (!queue.isEmpty()) {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        }

        pw.flush();
    }

    static class Process {
        String name;
        int time;

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

    static class Queue {
        Process[] Q;
        int lastIndex;
        int head;
        int tail;

        Queue(int n) {
            Q = new Process[n + 1];
            lastIndex = n;
            head = 0;
            tail = 0;
        }

        void enqueue(Process x) {
            Q[tail++] = new Process(x.name, x.time);
            if (tail > lastIndex)
                tail = 0;
        }

        Process dequeue() {
            Process x = Q[head++];
            if (head > lastIndex)
                head = 0;
            return x;
        }

        boolean isEmpty() {
            return head == tail ? true : false;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.nextInt();

        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        }

        int time = 0;
        while (!queue.isEmpty()) {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        }

        pw.flush();
    }

    static class Process {
        String name;
        int time;

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

    static class Queue {
        Process[] Q;
        int lastIndex;
        int head;
        int tail;

        Queue(int n) {
            Q = new Process[n + 1];
            lastIndex = n;
            head = 0;
            tail = 0;
        }

        void enqueue(Process x) {
            Q[tail++] = new Process(x.name, x.time);
            if (tail > lastIndex)
                tail = 0;
        }

        Process dequeue() {
            Process x = Q[head++];
            if (head > lastIndex)
                head = 0;
            return x;
        }

        boolean isEmpty() {
            return head == tail ? true : false;
        }
    }
} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.nextInt();

        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int time = sc.nextInt();
            Process x = new Process(name, time);
            queue.enqueue(x);
        }

        int time = 0;
        while (!queue.isEmpty()) {
            Process x = queue.dequeue();
            if (x.time - q <= 0) {
                time += x.time;
                pw.print(x.name + " ");
                pw.println(time);
            } else {
                time += q;
                x.time -= q;
                queue.enqueue(x);
            }
        }

        pw.flush();
    }

    static class Process {
        String name;
        int time;

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

    static class Queue {
        Process[] Q;
        int lastIndex;
        int head;
        int tail;

        Queue(int n) {
            Q = new Process[n + 1];
            lastIndex = n;
            head = 0;
            tail = 0;
        }

        void enqueue(Process x) {
            Q[tail++] = new Process(x.name, x.time);
            if (tail > lastIndex)
                tail = 0;
        }

        Process dequeue() {
            Process x = Q[head++];
            if (head > lastIndex)
                head = 0;
            return x;
        }

        boolean isEmpty() {
            return head == tail ? true : false;
        }
    }
}
