import java.util.*;

class Queue {
    static int top = 0;
    static int time = 0;
    static int n, q;
    static String[] label;
    static int[] value;
    public static void main() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt()-1;
        q = sc.nextInt();
        label = new String[1000000];
        value = new int[1000000];
        for (int i = 0; i <= n; i++) {
            label[i] = sc.next();
            value[i] = sc.nextInt();
        }
        sc.close();
        process();   
    }

    static void process() {
        while (top <= n) {
            int topItem = pop();
            if (topItem <= q) {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } else {
                time += q;
                push(topItem - q);
            }
        }
    }
    
    static int pop() {
        return value[top++];
    }

    static void push(int x) {
        label[++n] = label[top-1];
        value[n] = x;
    }
}

public class Main {
    public static void main(String[] args) {
        Queue que = new Queue();
        que.main();
    }
} import java.util.*; util.* java class Queue {
    static int top = 0;
    static int time = 0;
    static int n, q;
    static String[] label;
    static int[] value;
    public static void main() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt()-1;
        q = sc.nextInt();
        label = new String[1000000];
        value = new int[1000000];
        for (int i = 0; i <= n; i++) {
            label[i] = sc.next();
            value[i] = sc.nextInt();
        }
        sc.close();
        process();   
    }

    static void process() {
        while (top <= n) {
            int topItem = pop();
            if (topItem <= q) {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } else {
                time += q;
                push(topItem - q);
            }
        }
    }
    
    static int pop() {
        return value[top++];
    }

    static void push(int x) {
        label[++n] = label[top-1];
        value[n] = x;
    }
} Queue static int top = 0; top 0 static int time = 0; time 0 static int n n q; q static String[] label; label static int[] value; value public static void main() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt()-1;
        q = sc.nextInt();
        label = new String[1000000];
        value = new int[1000000];
        for (int i = 0; i <= n; i++) {
            label[i] = sc.next();
            value[i] = sc.nextInt();
        }
        sc.close();
        process();   
    } main {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt()-1;
        q = sc.nextInt();
        label = new String[1000000];
        value = new int[1000000];
        for (int i = 0; i <= n; i++) {
            label[i] = sc.next();
            value[i] = sc.nextInt();
        }
        sc.close();
        process();   
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt()-1 n sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 q = sc.nextInt() q sc.nextInt() sc.nextInt sc label = new String[1000000] label new String[1000000] 1000000 value = new int[1000000] value new int[1000000] 1000000 for (int i = 0; i <= n; i++) {
            label[i] = sc.next();
            value[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i <= n i n i++ i++ i {
            label[i] = sc.next();
            value[i] = sc.nextInt();
        } {
            label[i] = sc.next();
            value[i] = sc.nextInt();
        } label[i] = sc.next() label[i] label i sc.next() sc.next sc value[i] = sc.nextInt() value[i] value i sc.nextInt() sc.nextInt sc sc.close() sc.close sc process() process static void process() {
        while (top <= n) {
            int topItem = pop();
            if (topItem <= q) {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } else {
                time += q;
                push(topItem - q);
            }
        }
    } process {
        while (top <= n) {
            int topItem = pop();
            if (topItem <= q) {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } else {
                time += q;
                push(topItem - q);
            }
        }
    } while (top <= n) {
            int topItem = pop();
            if (topItem <= q) {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } else {
                time += q;
                push(topItem - q);
            }
        } top <= n top n {
            int topItem = pop();
            if (topItem <= q) {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } else {
                time += q;
                push(topItem - q);
            }
        } int topItem = pop(); topItem pop() pop if (topItem <= q) {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } else {
                time += q;
                push(topItem - q);
            } topItem <= q topItem q {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } time += topItem time topItem System.out.println(label[top-1] + " " + time) System.out.println System.out System System.out label[top-1] + " " + time label[top-1] + " " + time label[top-1] label top-1 top 1 " " time {
                time += q;
                push(topItem - q);
            } time += q time q push(topItem - q) push topItem - q topItem q static int pop() {
        return value[top++];
    } pop {
        return value[top++];
    } return value[top++]; value[top++] value top++ top static void push(int x) {
        label[++n] = label[top-1];
        value[n] = x;
    } push {
        label[++n] = label[top-1];
        value[n] = x;
    } label[++n] = label[top-1] label[++n] label ++n n label[top-1] label top-1 top 1 value[n] = x value[n] value n x int x x public class Main {
    public static void main(String[] args) {
        Queue que = new Queue();
        que.main();
    }
} Main public static void main(String[] args) {
        Queue que = new Queue();
        que.main();
    } main {
        Queue que = new Queue();
        que.main();
    } Queue que = new Queue(); que new Queue() que.main() que.main que String[] args args public class Main {
    public static void main(String[] args) {
        Queue que = new Queue();
        que.main();
    }
} public class Main {
    public static void main(String[] args) {
        Queue que = new Queue();
        que.main();
    }
} Main
import java.util.*;

class Queue {
    static int top = 0;
    static int time = 0;
    static int n, q;
    static String[] label;
    static int[] value;
    public static void main() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt()-1;
        q = sc.nextInt();
        label = new String[1000000];
        value = new int[1000000];
        for (int i = 0; i <= n; i++) {
            label[i] = sc.next();
            value[i] = sc.nextInt();
        }
        sc.close();
        process();   
    }

    static void process() {
        while (top <= n) {
            int topItem = pop();
            if (topItem <= q) {
                time += topItem;
                System.out.println(label[top-1] + " " + time);
            } else {
                time += q;
                push(topItem - q);
            }
        }
    }
    
    static int pop() {
        return value[top++];
    }

    static void push(int x) {
        label[++n] = label[top-1];
        value[n] = x;
    }
}

public class Main {
    public static void main(String[] args) {
        Queue que = new Queue();
        que.main();
    }
}
