import java.util.Scanner;

class Queue {
    int[] data;
    int maxLen;
    int lastEnqueue;
    int queueSize;

    public Queue(int maxLen) {
        this.data = new int[maxLen];
        this.maxLen = maxLen;
        this.lastEnqueue = maxLen - 1;
        this.queueSize = 0;
    }

    public void enqueue(int num) {
        this.queueSize++;
        this.lastEnqueue++;
        if (this.lastEnqueue >= this.maxLen) {
            this.lastEnqueue = 0;
        }
        this.data[this.lastEnqueue] = num;
    }

    public int dequeue() {
        if (this.queueSize == 0) {
            return -1;
        }

        int dequeueIndex = this.lastEnqueue - this.queueSize + 1;
        if (dequeueIndex < 0) {
            dequeueIndex += this.maxLen;
        }
        int num = this.data[dequeueIndex];
        this.queueSize--;
        return num;
    }
}

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nq = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nq[0]); // num processes
        int q = Integer.parseInt(nq[1]); // quoantum number

        String[] names = new String[n];
        int[] times = new int[n];
        for (int i = 0; i < n; i++) {
            String[] nameTime = scanner.nextLine().split(" ", 2);
            names[i] = nameTime[0];
            times[i] = Integer.parseInt(nameTime[1]);
        }

        new Main().printProcessFinishes(n, q, names, times);
    }

    private void printProcessFinishes(int n, int q, String[] names, int[] times) {
        int now = 0;
        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            queue.enqueue(i);
        }

        int dequeued;
        while ((dequeued = queue.dequeue()) >= 0) {
            if (times[dequeued] <= q) {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } else {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            }
        }
    }
}
 import java.util.Scanner; Scanner java.util class Queue {
    int[] data;
    int maxLen;
    int lastEnqueue;
    int queueSize;

    public Queue(int maxLen) {
        this.data = new int[maxLen];
        this.maxLen = maxLen;
        this.lastEnqueue = maxLen - 1;
        this.queueSize = 0;
    }

    public void enqueue(int num) {
        this.queueSize++;
        this.lastEnqueue++;
        if (this.lastEnqueue >= this.maxLen) {
            this.lastEnqueue = 0;
        }
        this.data[this.lastEnqueue] = num;
    }

    public int dequeue() {
        if (this.queueSize == 0) {
            return -1;
        }

        int dequeueIndex = this.lastEnqueue - this.queueSize + 1;
        if (dequeueIndex < 0) {
            dequeueIndex += this.maxLen;
        }
        int num = this.data[dequeueIndex];
        this.queueSize--;
        return num;
    }
} Queue int[] data; data int maxLen; maxLen int lastEnqueue; lastEnqueue int queueSize; queueSize public Queue(int maxLen) {
        this.data = new int[maxLen];
        this.maxLen = maxLen;
        this.lastEnqueue = maxLen - 1;
        this.queueSize = 0;
    } Queue {
        this.data = new int[maxLen];
        this.maxLen = maxLen;
        this.lastEnqueue = maxLen - 1;
        this.queueSize = 0;
    } this.data = new int[maxLen] this.data this this.data new int[maxLen] maxLen this.maxLen = maxLen this.maxLen this this.maxLen maxLen this.lastEnqueue = maxLen - 1 this.lastEnqueue this this.lastEnqueue maxLen - 1 maxLen 1 this.queueSize = 0 this.queueSize this this.queueSize 0 int maxLen maxLen public void enqueue(int num) {
        this.queueSize++;
        this.lastEnqueue++;
        if (this.lastEnqueue >= this.maxLen) {
            this.lastEnqueue = 0;
        }
        this.data[this.lastEnqueue] = num;
    } enqueue {
        this.queueSize++;
        this.lastEnqueue++;
        if (this.lastEnqueue >= this.maxLen) {
            this.lastEnqueue = 0;
        }
        this.data[this.lastEnqueue] = num;
    } this.queueSize++ this.queueSize this this.queueSize this.lastEnqueue++ this.lastEnqueue this this.lastEnqueue if (this.lastEnqueue >= this.maxLen) {
            this.lastEnqueue = 0;
        } this.lastEnqueue >= this.maxLen this.lastEnqueue this this.lastEnqueue this.maxLen this this.maxLen {
            this.lastEnqueue = 0;
        } this.lastEnqueue = 0 this.lastEnqueue this this.lastEnqueue 0 this.data[this.lastEnqueue] = num this.data[this.lastEnqueue] this.data this this.data this.lastEnqueue this this.lastEnqueue num int num num public int dequeue() {
        if (this.queueSize == 0) {
            return -1;
        }

        int dequeueIndex = this.lastEnqueue - this.queueSize + 1;
        if (dequeueIndex < 0) {
            dequeueIndex += this.maxLen;
        }
        int num = this.data[dequeueIndex];
        this.queueSize--;
        return num;
    } dequeue {
        if (this.queueSize == 0) {
            return -1;
        }

        int dequeueIndex = this.lastEnqueue - this.queueSize + 1;
        if (dequeueIndex < 0) {
            dequeueIndex += this.maxLen;
        }
        int num = this.data[dequeueIndex];
        this.queueSize--;
        return num;
    } if (this.queueSize == 0) {
            return -1;
        } this.queueSize == 0 this.queueSize this this.queueSize 0 {
            return -1;
        } return -1; -1 1 int dequeueIndex = this.lastEnqueue - this.queueSize + 1; dequeueIndex this.lastEnqueue - this.queueSize + 1 this.lastEnqueue - this.queueSize this.lastEnqueue this this.lastEnqueue this.queueSize this this.queueSize 1 if (dequeueIndex < 0) {
            dequeueIndex += this.maxLen;
        } dequeueIndex < 0 dequeueIndex 0 {
            dequeueIndex += this.maxLen;
        } dequeueIndex += this.maxLen dequeueIndex this.maxLen this this.maxLen int num = this.data[dequeueIndex]; num this.data[dequeueIndex] this.data this this.data dequeueIndex this.queueSize-- this.queueSize this this.queueSize return num; num class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nq = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nq[0]); // num processes
        int q = Integer.parseInt(nq[1]); // quoantum number

        String[] names = new String[n];
        int[] times = new int[n];
        for (int i = 0; i < n; i++) {
            String[] nameTime = scanner.nextLine().split(" ", 2);
            names[i] = nameTime[0];
            times[i] = Integer.parseInt(nameTime[1]);
        }

        new Main().printProcessFinishes(n, q, names, times);
    }

    private void printProcessFinishes(int n, int q, String[] names, int[] times) {
        int now = 0;
        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            queue.enqueue(i);
        }

        int dequeued;
        while ((dequeued = queue.dequeue()) >= 0) {
            if (times[dequeued] <= q) {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } else {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nq = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nq[0]); // num processes
        int q = Integer.parseInt(nq[1]); // quoantum number

        String[] names = new String[n];
        int[] times = new int[n];
        for (int i = 0; i < n; i++) {
            String[] nameTime = scanner.nextLine().split(" ", 2);
            names[i] = nameTime[0];
            times[i] = Integer.parseInt(nameTime[1]);
        }

        new Main().printProcessFinishes(n, q, names, times);
    } main {
        Scanner scanner = new Scanner(System.in);
        String[] nq = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nq[0]); // num processes
        int q = Integer.parseInt(nq[1]); // quoantum number

        String[] names = new String[n];
        int[] times = new int[n];
        for (int i = 0; i < n; i++) {
            String[] nameTime = scanner.nextLine().split(" ", 2);
            names[i] = nameTime[0];
            times[i] = Integer.parseInt(nameTime[1]);
        }

        new Main().printProcessFinishes(n, q, names, times);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] nq = scanner.nextLine().split(" ", 2); nq scanner.nextLine().split(" ", 2) scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " 2 int n = Integer.parseInt(nq[0]); n Integer.parseInt(nq[0]) Integer.parseInt Integer nq[0] nq 0 int q = Integer.parseInt(nq[1]); q Integer.parseInt(nq[1]) Integer.parseInt Integer nq[1] nq 1 String[] names = new String[n]; names new String[n] n int[] times = new int[n]; times new int[n] n for (int i = 0; i < n; i++) {
            String[] nameTime = scanner.nextLine().split(" ", 2);
            names[i] = nameTime[0];
            times[i] = Integer.parseInt(nameTime[1]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String[] nameTime = scanner.nextLine().split(" ", 2);
            names[i] = nameTime[0];
            times[i] = Integer.parseInt(nameTime[1]);
        } {
            String[] nameTime = scanner.nextLine().split(" ", 2);
            names[i] = nameTime[0];
            times[i] = Integer.parseInt(nameTime[1]);
        } String[] nameTime = scanner.nextLine().split(" ", 2); nameTime scanner.nextLine().split(" ", 2) scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " 2 names[i] = nameTime[0] names[i] names i nameTime[0] nameTime 0 times[i] = Integer.parseInt(nameTime[1]) times[i] times i Integer.parseInt(nameTime[1]) Integer.parseInt Integer nameTime[1] nameTime 1 new Main().printProcessFinishes(n, q, names, times) new Main().printProcessFinishes new Main() n q names times String[] args args private void printProcessFinishes(int n, int q, String[] names, int[] times) {
        int now = 0;
        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            queue.enqueue(i);
        }

        int dequeued;
        while ((dequeued = queue.dequeue()) >= 0) {
            if (times[dequeued] <= q) {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } else {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            }
        }
    } printProcessFinishes {
        int now = 0;
        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            queue.enqueue(i);
        }

        int dequeued;
        while ((dequeued = queue.dequeue()) >= 0) {
            if (times[dequeued] <= q) {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } else {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            }
        }
    } int now = 0; now 0 Queue queue = new Queue(n); queue new Queue(n) for (int i = 0; i < n; i++) {
            queue.enqueue(i);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            queue.enqueue(i);
        } {
            queue.enqueue(i);
        } queue.enqueue(i) queue.enqueue queue i int dequeued; dequeued while ((dequeued = queue.dequeue()) >= 0) {
            if (times[dequeued] <= q) {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } else {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            }
        } (dequeued = queue.dequeue()) >= 0 (dequeued = queue.dequeue()) dequeued queue.dequeue() queue.dequeue queue 0 {
            if (times[dequeued] <= q) {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } else {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            }
        } if (times[dequeued] <= q) {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } else {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            } times[dequeued] <= q times[dequeued] times dequeued q {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } now += times[dequeued] now times[dequeued] times dequeued System.out.print(names[dequeued]) System.out.print System.out System System.out names[dequeued] names dequeued System.out.print(" ") System.out.print System.out System System.out " " System.out.println(now) System.out.println System.out System System.out now {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            } now += q now q times[dequeued] -= q times[dequeued] times dequeued q queue.enqueue(dequeued) queue.enqueue queue dequeued int n n int q q String[] names names int[] times times
import java.util.Scanner;

class Queue {
    int[] data;
    int maxLen;
    int lastEnqueue;
    int queueSize;

    public Queue(int maxLen) {
        this.data = new int[maxLen];
        this.maxLen = maxLen;
        this.lastEnqueue = maxLen - 1;
        this.queueSize = 0;
    }

    public void enqueue(int num) {
        this.queueSize++;
        this.lastEnqueue++;
        if (this.lastEnqueue >= this.maxLen) {
            this.lastEnqueue = 0;
        }
        this.data[this.lastEnqueue] = num;
    }

    public int dequeue() {
        if (this.queueSize == 0) {
            return -1;
        }

        int dequeueIndex = this.lastEnqueue - this.queueSize + 1;
        if (dequeueIndex < 0) {
            dequeueIndex += this.maxLen;
        }
        int num = this.data[dequeueIndex];
        this.queueSize--;
        return num;
    }
}

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nq = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nq[0]); // num processes
        int q = Integer.parseInt(nq[1]); // quoantum number

        String[] names = new String[n];
        int[] times = new int[n];
        for (int i = 0; i < n; i++) {
            String[] nameTime = scanner.nextLine().split(" ", 2);
            names[i] = nameTime[0];
            times[i] = Integer.parseInt(nameTime[1]);
        }

        new Main().printProcessFinishes(n, q, names, times);
    }

    private void printProcessFinishes(int n, int q, String[] names, int[] times) {
        int now = 0;
        Queue queue = new Queue(n);
        for (int i = 0; i < n; i++) {
            queue.enqueue(i);
        }

        int dequeued;
        while ((dequeued = queue.dequeue()) >= 0) {
            if (times[dequeued] <= q) {
                now += times[dequeued];
                System.out.print(names[dequeued]);
                System.out.print(" ");
                System.out.println(now);
            } else {
                now += q;
                times[dequeued] -= q;
                queue.enqueue(dequeued);
            }
        }
    }
}

