import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int quantum = Integer.parseInt(scanner.next());
        int sum = 0;
        Queue queue = new Queue();
        for (int i = 0; i < size; i++) {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        }

        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        }
    }

    static class Queue {
        static final int SIZE = 100000;
        Process[] array = new Process[SIZE];
        int head = 0;
        int tail = 0;

        Process dequeue() {
            if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            }
            Process value = array[tail];
            tail += 1;
            if (tail == SIZE) {
                tail -= SIZE;
            }
            return value;
        }

        void enqueue(Process process) {
            if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            }
            array[head] = process;
            head += 1;
            if (head == SIZE) {
                head -= SIZE;
            }
        }

        boolean isFull() {
            return head + 1 == (tail % SIZE);
        }

        boolean isEmpty() {
            return head == tail;
        }
    }

    static class Process {
        String name;
        int quantum;

        Process(String name, int quantum) {
            this.name = name;
            this.quantum = quantum;
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int quantum = Integer.parseInt(scanner.next());
        int sum = 0;
        Queue queue = new Queue();
        for (int i = 0; i < size; i++) {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        }

        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        }
    }

    static class Queue {
        static final int SIZE = 100000;
        Process[] array = new Process[SIZE];
        int head = 0;
        int tail = 0;

        Process dequeue() {
            if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            }
            Process value = array[tail];
            tail += 1;
            if (tail == SIZE) {
                tail -= SIZE;
            }
            return value;
        }

        void enqueue(Process process) {
            if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            }
            array[head] = process;
            head += 1;
            if (head == SIZE) {
                head -= SIZE;
            }
        }

        boolean isFull() {
            return head + 1 == (tail % SIZE);
        }

        boolean isEmpty() {
            return head == tail;
        }
    }

    static class Process {
        String name;
        int quantum;

        Process(String name, int quantum) {
            this.name = name;
            this.quantum = quantum;
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int quantum = Integer.parseInt(scanner.next());
        int sum = 0;
        Queue queue = new Queue();
        for (int i = 0; i < size; i++) {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        }

        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int quantum = Integer.parseInt(scanner.next());
        int sum = 0;
        Queue queue = new Queue();
        for (int i = 0; i < size; i++) {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        }

        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int size = Integer.parseInt(scanner.next()); size Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int quantum = Integer.parseInt(scanner.next()); quantum Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int sum = 0; sum 0 Queue queue = new Queue(); queue new Queue() for (int i = 0; i < size; i++) {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        } int i = 0; int i = 0; i 0 i < size i size i++ i++ i {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        } {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        } String name = scanner.next(); name scanner.next() scanner.next scanner int time = Integer.parseInt(scanner.next()); time Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            } time <= quantum time quantum {
                sum += time;
                System.out.println(name + " " + sum);
            } sum += time sum time System.out.println(name + " " + sum) System.out.println System.out System System.out name + " " + sum name + " " + sum name " " sum {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            } sum += quantum sum quantum queue.enqueue(new Process(name, time - quantum)) queue.enqueue queue new Process(name, time - quantum) while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        } Process process = queue.dequeue(); process queue.dequeue() queue.dequeue queue if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            } process.quantum <= quantum process.quantum process process.quantum quantum {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } sum += process.quantum sum process.quantum process process.quantum System.out.println(process.name + " " + sum) System.out.println System.out System System.out process.name + " " + sum process.name + " " + sum process.name process process.name " " sum {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            } sum += quantum sum quantum queue.enqueue(new Process(process.name, process.quantum - quantum)) queue.enqueue queue new Process(process.name, process.quantum - quantum) String[] args args static class Queue {
        static final int SIZE = 100000;
        Process[] array = new Process[SIZE];
        int head = 0;
        int tail = 0;

        Process dequeue() {
            if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            }
            Process value = array[tail];
            tail += 1;
            if (tail == SIZE) {
                tail -= SIZE;
            }
            return value;
        }

        void enqueue(Process process) {
            if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            }
            array[head] = process;
            head += 1;
            if (head == SIZE) {
                head -= SIZE;
            }
        }

        boolean isFull() {
            return head + 1 == (tail % SIZE);
        }

        boolean isEmpty() {
            return head == tail;
        }
    } Queue static final int SIZE = 100000; SIZE 100000 Process[] array = new Process[SIZE]; array new Process[SIZE] SIZE int head = 0; head 0 int tail = 0; tail 0 Process dequeue() {
            if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            }
            Process value = array[tail];
            tail += 1;
            if (tail == SIZE) {
                tail -= SIZE;
            }
            return value;
        } dequeue {
            if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            }
            Process value = array[tail];
            tail += 1;
            if (tail == SIZE) {
                tail -= SIZE;
            }
            return value;
        } if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            } isEmpty() isEmpty {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            } throw new IllegalStateException("You dequeued from empty " +
                        "queue."); new IllegalStateException("You dequeued from empty " +
                        "queue.") Process value = array[tail]; value array[tail] array tail tail += 1 tail 1 if (tail == SIZE) {
                tail -= SIZE;
            } tail == SIZE tail SIZE {
                tail -= SIZE;
            } tail -= SIZE tail SIZE return value; value void enqueue(Process process) {
            if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            }
            array[head] = process;
            head += 1;
            if (head == SIZE) {
                head -= SIZE;
            }
        } enqueue {
            if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            }
            array[head] = process;
            head += 1;
            if (head == SIZE) {
                head -= SIZE;
            }
        } if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            } isFull() isFull {
                throw new IllegalStateException("You enqueued to full queue.");
            } throw new IllegalStateException("You enqueued to full queue."); new IllegalStateException("You enqueued to full queue.") array[head] = process array[head] array head process head += 1 head 1 if (head == SIZE) {
                head -= SIZE;
            } head == SIZE head SIZE {
                head -= SIZE;
            } head -= SIZE head SIZE Process process process boolean isFull() {
            return head + 1 == (tail % SIZE);
        } isFull {
            return head + 1 == (tail % SIZE);
        } return head + 1 == (tail % SIZE); head + 1 == (tail % SIZE) head + 1 head 1 (tail % SIZE) tail SIZE boolean isEmpty() {
            return head == tail;
        } isEmpty {
            return head == tail;
        } return head == tail; head == tail head tail static class Process {
        String name;
        int quantum;

        Process(String name, int quantum) {
            this.name = name;
            this.quantum = quantum;
        }
    } Process String name; name int quantum; quantum Process(String name, int quantum) {
            this.name = name;
            this.quantum = quantum;
        } Process {
            this.name = name;
            this.quantum = quantum;
        } this.name = name this.name this this.name name this.quantum = quantum this.quantum this this.quantum quantum String name name int quantum quantum public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int quantum = Integer.parseInt(scanner.next());
        int sum = 0;
        Queue queue = new Queue();
        for (int i = 0; i < size; i++) {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        }

        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        }
    }

    static class Queue {
        static final int SIZE = 100000;
        Process[] array = new Process[SIZE];
        int head = 0;
        int tail = 0;

        Process dequeue() {
            if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            }
            Process value = array[tail];
            tail += 1;
            if (tail == SIZE) {
                tail -= SIZE;
            }
            return value;
        }

        void enqueue(Process process) {
            if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            }
            array[head] = process;
            head += 1;
            if (head == SIZE) {
                head -= SIZE;
            }
        }

        boolean isFull() {
            return head + 1 == (tail % SIZE);
        }

        boolean isEmpty() {
            return head == tail;
        }
    }

    static class Process {
        String name;
        int quantum;

        Process(String name, int quantum) {
            this.name = name;
            this.quantum = quantum;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int quantum = Integer.parseInt(scanner.next());
        int sum = 0;
        Queue queue = new Queue();
        for (int i = 0; i < size; i++) {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        }

        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        }
    }

    static class Queue {
        static final int SIZE = 100000;
        Process[] array = new Process[SIZE];
        int head = 0;
        int tail = 0;

        Process dequeue() {
            if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            }
            Process value = array[tail];
            tail += 1;
            if (tail == SIZE) {
                tail -= SIZE;
            }
            return value;
        }

        void enqueue(Process process) {
            if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            }
            array[head] = process;
            head += 1;
            if (head == SIZE) {
                head -= SIZE;
            }
        }

        boolean isFull() {
            return head + 1 == (tail % SIZE);
        }

        boolean isEmpty() {
            return head == tail;
        }
    }

    static class Process {
        String name;
        int quantum;

        Process(String name, int quantum) {
            this.name = name;
            this.quantum = quantum;
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int quantum = Integer.parseInt(scanner.next());
        int sum = 0;
        Queue queue = new Queue();
        for (int i = 0; i < size; i++) {
            String name = scanner.next();
            int time = Integer.parseInt(scanner.next());
            if (time <= quantum) {
                sum += time;
                System.out.println(name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(name, time - quantum));
            }
        }

        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            if (process.quantum <= quantum) {
                sum += process.quantum;
                System.out.println(process.name + " " + sum);
            } else {
                sum += quantum;
                queue.enqueue(new Process(process.name, process.quantum - quantum));
            }
        }
    }

    static class Queue {
        static final int SIZE = 100000;
        Process[] array = new Process[SIZE];
        int head = 0;
        int tail = 0;

        Process dequeue() {
            if (isEmpty()) {
                throw new IllegalStateException("You dequeued from empty " +
                        "queue.");
            }
            Process value = array[tail];
            tail += 1;
            if (tail == SIZE) {
                tail -= SIZE;
            }
            return value;
        }

        void enqueue(Process process) {
            if (isFull()) {
                throw new IllegalStateException("You enqueued to full queue.");
            }
            array[head] = process;
            head += 1;
            if (head == SIZE) {
                head -= SIZE;
            }
        }

        boolean isFull() {
            return head + 1 == (tail % SIZE);
        }

        boolean isEmpty() {
            return head == tail;
        }
    }

    static class Process {
        String name;
        int quantum;

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