import java.util.Scanner;

class Pair {
    String name;
    int time;
}

public class Main {
    static int LEN;
    static int head;
    static int tail;
    static Pair[] pairs;

    // データの追加
    public static void enqueue(Pair x) {
        pairs[tail] = x;
        tail = (tail + 1) % LEN;
    }

    // データを取り出す
    public static Pair dequeue() {
        Pair x = pairs[head];
        head = (head + 1) % LEN;
        return x;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // n個のプロセス
        int q = sc.nextInt(); // 最大実行時間
        LEN = 100005;
        pairs = new Pair[LEN];
        for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        }
        head = 1;
        tail = n + 1;
        int now = 0;
        while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        }
        sc.close();
    }

} import java.util.Scanner; Scanner java.util class Pair {
    String name;
    int time;
} Pair String name; name int time; time public class Main {
    static int LEN;
    static int head;
    static int tail;
    static Pair[] pairs;

    // データの追加
    public static void enqueue(Pair x) {
        pairs[tail] = x;
        tail = (tail + 1) % LEN;
    }

    // データを取り出す
    public static Pair dequeue() {
        Pair x = pairs[head];
        head = (head + 1) % LEN;
        return x;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // n個のプロセス
        int q = sc.nextInt(); // 最大実行時間
        LEN = 100005;
        pairs = new Pair[LEN];
        for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        }
        head = 1;
        tail = n + 1;
        int now = 0;
        while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        }
        sc.close();
    }

} Main static int LEN; LEN static int head; head static int tail; tail static Pair[] pairs; pairs // データの追加
    public static void enqueue(Pair x) {
        pairs[tail] = x;
        tail = (tail + 1) % LEN;
    } enqueue {
        pairs[tail] = x;
        tail = (tail + 1) % LEN;
    } pairs[tail] = x pairs[tail] pairs tail x tail = (tail + 1) % LEN tail (tail + 1) % LEN (tail + 1) tail 1 LEN Pair x x // データを取り出す
    public static Pair dequeue() {
        Pair x = pairs[head];
        head = (head + 1) % LEN;
        return x;
    } dequeue {
        Pair x = pairs[head];
        head = (head + 1) % LEN;
        return x;
    } Pair x = pairs[head]; x pairs[head] pairs head head = (head + 1) % LEN head (head + 1) % LEN (head + 1) head 1 LEN return x; x public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // n個のプロセス
        int q = sc.nextInt(); // 最大実行時間
        LEN = 100005;
        pairs = new Pair[LEN];
        for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        }
        head = 1;
        tail = n + 1;
        int now = 0;
        while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        }
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // n個のプロセス
        int q = sc.nextInt(); // 最大実行時間
        LEN = 100005;
        pairs = new Pair[LEN];
        for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        }
        head = 1;
        tail = n + 1;
        int now = 0;
        while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        }
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc LEN = 100005 LEN 100005 pairs = new Pair[LEN] pairs new Pair[LEN] LEN for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        } {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        } pairs[i] = new Pair() pairs[i] pairs i new Pair() pairs[i].name = sc.next() pairs[i].name pairs[i] pairs i pairs[i].name sc.next() sc.next sc pairs[i].time = sc.nextInt() pairs[i].time pairs[i] pairs i pairs[i].time sc.nextInt() sc.nextInt sc head = 1 head 1 tail = n + 1 tail n + 1 n 1 int now = 0; now 0 while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        } tail != head tail head {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        } Pair u = dequeue(); u dequeue() dequeue if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            } u.time - q > 0 u.time - q u.time u u.time q 0 {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } now += q now q u.time = u.time - q u.time u u.time u.time - q u.time u u.time q enqueue(u) enqueue u {
                now += u.time;
                System.out.println(u.name + " " + now);
            } now += u.time now u.time u u.time System.out.println(u.name + " " + now) System.out.println System.out System System.out u.name + " " + now u.name + " " + now u.name u u.name " " now sc.close() sc.close sc String[] args args public class Main {
    static int LEN;
    static int head;
    static int tail;
    static Pair[] pairs;

    // データの追加
    public static void enqueue(Pair x) {
        pairs[tail] = x;
        tail = (tail + 1) % LEN;
    }

    // データを取り出す
    public static Pair dequeue() {
        Pair x = pairs[head];
        head = (head + 1) % LEN;
        return x;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // n個のプロセス
        int q = sc.nextInt(); // 最大実行時間
        LEN = 100005;
        pairs = new Pair[LEN];
        for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        }
        head = 1;
        tail = n + 1;
        int now = 0;
        while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        }
        sc.close();
    }

} public class Main {
    static int LEN;
    static int head;
    static int tail;
    static Pair[] pairs;

    // データの追加
    public static void enqueue(Pair x) {
        pairs[tail] = x;
        tail = (tail + 1) % LEN;
    }

    // データを取り出す
    public static Pair dequeue() {
        Pair x = pairs[head];
        head = (head + 1) % LEN;
        return x;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // n個のプロセス
        int q = sc.nextInt(); // 最大実行時間
        LEN = 100005;
        pairs = new Pair[LEN];
        for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        }
        head = 1;
        tail = n + 1;
        int now = 0;
        while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        }
        sc.close();
    }

} Main
import java.util.Scanner;

class Pair {
    String name;
    int time;
}

public class Main {
    static int LEN;
    static int head;
    static int tail;
    static Pair[] pairs;

    // データの追加
    public static void enqueue(Pair x) {
        pairs[tail] = x;
        tail = (tail + 1) % LEN;
    }

    // データを取り出す
    public static Pair dequeue() {
        Pair x = pairs[head];
        head = (head + 1) % LEN;
        return x;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // n個のプロセス
        int q = sc.nextInt(); // 最大実行時間
        LEN = 100005;
        pairs = new Pair[LEN];
        for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        }
        head = 1;
        tail = n + 1;
        int now = 0;
        while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        }
        sc.close();
    }

}
