import java.util.Scanner;

class Main {
    static int n;
    static int q;
    static int head;
    static int tail;
    static Process[] a;
    static int elaps;

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        q = sc.nextInt();
        a = new Process[n + 1];

        for (int i = 0; i < n; i++) {
            a[i] = new Process(sc.next(), sc.nextInt());
        }

        head = 0;
        tail = n;

        while(head != tail) {
            Process p = dequeue();
            int time = getMin(p.time, q);
            p.time -= time;
            elaps += time;
            if (p.time > 0) {
                enqueue(p);
            } else {
                System.out.printf("%s %d\n", p.name, elaps);
            }
        }
    }

    public static Process dequeue() {
        Process p = a[head];
        head = (head + 1) % (n + 1);
        return p;
    }

    public static void enqueue(Process p) {
        a[tail] = p;
        tail = (tail + 1) % (n + 1);
    }

    public static int getMin(int a, int b) {
        if (a > b) {
            return b;
        }
        return a;
    }
}

class Process {
    String name;
    int time;
    public Process(String name, int time) {
        this.name = name;
        this.time = time;
    }
}
 import java.util.Scanner; Scanner java.util class Main {
    static int n;
    static int q;
    static int head;
    static int tail;
    static Process[] a;
    static int elaps;

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        q = sc.nextInt();
        a = new Process[n + 1];

        for (int i = 0; i < n; i++) {
            a[i] = new Process(sc.next(), sc.nextInt());
        }

        head = 0;
        tail = n;

        while(head != tail) {
            Process p = dequeue();
            int time = getMin(p.time, q);
            p.time -= time;
            elaps += time;
            if (p.time > 0) {
                enqueue(p);
            } else {
                System.out.printf("%s %d\n", p.name, elaps);
            }
        }
    }

    public static Process dequeue() {
        Process p = a[head];
        head = (head + 1) % (n + 1);
        return p;
    }

    public static void enqueue(Process p) {
        a[tail] = p;
        tail = (tail + 1) % (n + 1);
    }

    public static int getMin(int a, int b) {
        if (a > b) {
            return b;
        }
        return a;
    }
} Main static int n; n static int q; q static int head; head static int tail; tail static Process[] a; a static int elaps; elaps public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        q = sc.nextInt();
        a = new Process[n + 1];

        for (int i = 0; i < n; i++) {
            a[i] = new Process(sc.next(), sc.nextInt());
        }

        head = 0;
        tail = n;

        while(head != tail) {
            Process p = dequeue();
            int time = getMin(p.time, q);
            p.time -= time;
            elaps += time;
            if (p.time > 0) {
                enqueue(p);
            } else {
                System.out.printf("%s %d\n", p.name, elaps);
            }
        }
    } main {
        final Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        q = sc.nextInt();
        a = new Process[n + 1];

        for (int i = 0; i < n; i++) {
            a[i] = new Process(sc.next(), sc.nextInt());
        }

        head = 0;
        tail = n;

        while(head != tail) {
            Process p = dequeue();
            int time = getMin(p.time, q);
            p.time -= time;
            elaps += time;
            if (p.time > 0) {
                enqueue(p);
            } else {
                System.out.printf("%s %d\n", p.name, elaps);
            }
        }
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt() q sc.nextInt() sc.nextInt sc a = new Process[n + 1] a new Process[n + 1] n + 1 n 1 for (int i = 0; i < n; i++) {
            a[i] = new Process(sc.next(), sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = new Process(sc.next(), sc.nextInt());
        } {
            a[i] = new Process(sc.next(), sc.nextInt());
        } a[i] = new Process(sc.next(), sc.nextInt()) a[i] a i new Process(sc.next(), sc.nextInt()) head = 0 head 0 tail = n tail n while(head != tail) {
            Process p = dequeue();
            int time = getMin(p.time, q);
            p.time -= time;
            elaps += time;
            if (p.time > 0) {
                enqueue(p);
            } else {
                System.out.printf("%s %d\n", p.name, elaps);
            }
        } head != tail head tail {
            Process p = dequeue();
            int time = getMin(p.time, q);
            p.time -= time;
            elaps += time;
            if (p.time > 0) {
                enqueue(p);
            } else {
                System.out.printf("%s %d\n", p.name, elaps);
            }
        } Process p = dequeue(); p dequeue() dequeue int time = getMin(p.time, q); time getMin(p.time, q) getMin p.time p p.time q p.time -= time p.time p p.time time elaps += time elaps time if (p.time > 0) {
                enqueue(p);
            } else {
                System.out.printf("%s %d\n", p.name, elaps);
            } p.time > 0 p.time p p.time 0 {
                enqueue(p);
            } enqueue(p) enqueue p {
                System.out.printf("%s %d\n", p.name, elaps);
            } System.out.printf("%s %d\n", p.name, elaps) System.out.printf System.out System System.out "%s %d\n" p.name p p.name elaps String[] args args public static Process dequeue() {
        Process p = a[head];
        head = (head + 1) % (n + 1);
        return p;
    } dequeue {
        Process p = a[head];
        head = (head + 1) % (n + 1);
        return p;
    } Process p = a[head]; p a[head] a head head = (head + 1) % (n + 1) head (head + 1) % (n + 1) (head + 1) head 1 (n + 1) n 1 return p; p public static void enqueue(Process p) {
        a[tail] = p;
        tail = (tail + 1) % (n + 1);
    } enqueue {
        a[tail] = p;
        tail = (tail + 1) % (n + 1);
    } a[tail] = p a[tail] a tail p tail = (tail + 1) % (n + 1) tail (tail + 1) % (n + 1) (tail + 1) tail 1 (n + 1) n 1 Process p p public static int getMin(int a, int b) {
        if (a > b) {
            return b;
        }
        return a;
    } getMin {
        if (a > b) {
            return b;
        }
        return a;
    } if (a > b) {
            return b;
        } a > b a b {
            return b;
        } return b; b return a; a int a a int b b class Process {
    String name;
    int time;
    public Process(String name, int time) {
        this.name = name;
        this.time = time;
    }
} Process String name; name int time; time public Process(String name, int time) {
        this.name = name;
        this.time = time;
    } Process {
        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
import java.util.Scanner;

class Main {
    static int n;
    static int q;
    static int head;
    static int tail;
    static Process[] a;
    static int elaps;

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        q = sc.nextInt();
        a = new Process[n + 1];

        for (int i = 0; i < n; i++) {
            a[i] = new Process(sc.next(), sc.nextInt());
        }

        head = 0;
        tail = n;

        while(head != tail) {
            Process p = dequeue();
            int time = getMin(p.time, q);
            p.time -= time;
            elaps += time;
            if (p.time > 0) {
                enqueue(p);
            } else {
                System.out.printf("%s %d\n", p.name, elaps);
            }
        }
    }

    public static Process dequeue() {
        Process p = a[head];
        head = (head + 1) % (n + 1);
        return p;
    }

    public static void enqueue(Process p) {
        a[tail] = p;
        tail = (tail + 1) % (n + 1);
    }

    public static int getMin(int a, int b) {
        if (a > b) {
            return b;
        }
        return a;
    }
}

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

