import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> name = new LinkedList<>();
        Queue<Integer> time = new LinkedList<>();
        int a = in.nextInt();
        int b = in.nextInt();
        int timer = 0;

        for (int i = 0; i < a; i++) {
            name.add(in.next());
            time.add(in.nextInt());
        }
        while (name.size() != 0) {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        }
    }
}
 import java.util.*; util.* java public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> name = new LinkedList<>();
        Queue<Integer> time = new LinkedList<>();
        int a = in.nextInt();
        int b = in.nextInt();
        int timer = 0;

        for (int i = 0; i < a; i++) {
            name.add(in.next());
            time.add(in.nextInt());
        }
        while (name.size() != 0) {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> name = new LinkedList<>();
        Queue<Integer> time = new LinkedList<>();
        int a = in.nextInt();
        int b = in.nextInt();
        int timer = 0;

        for (int i = 0; i < a; i++) {
            name.add(in.next());
            time.add(in.nextInt());
        }
        while (name.size() != 0) {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        }
    } main {
        Scanner in = new Scanner(System.in);
        Queue<String> name = new LinkedList<>();
        Queue<Integer> time = new LinkedList<>();
        int a = in.nextInt();
        int b = in.nextInt();
        int timer = 0;

        for (int i = 0; i < a; i++) {
            name.add(in.next());
            time.add(in.nextInt());
        }
        while (name.size() != 0) {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        }
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) Queue<String> name = new LinkedList<>(); name new LinkedList<>() Queue<Integer> time = new LinkedList<>(); time new LinkedList<>() int a = in.nextInt(); a in.nextInt() in.nextInt in int b = in.nextInt(); b in.nextInt() in.nextInt in int timer = 0; timer 0 for (int i = 0; i < a; i++) {
            name.add(in.next());
            time.add(in.nextInt());
        } int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
            name.add(in.next());
            time.add(in.nextInt());
        } {
            name.add(in.next());
            time.add(in.nextInt());
        } name.add(in.next()) name.add name in.next() in.next in time.add(in.nextInt()) time.add time in.nextInt() in.nextInt in while (name.size() != 0) {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        } name.size() != 0 name.size() name.size name 0 {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        } if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            } time.peek() - b > 0 time.peek() - b time.peek() time.peek time b 0 {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } name.add(name.poll()) name.add name name.poll() name.poll name time.add(time.poll() - b) time.add time time.poll() - b time.poll() time.poll time b timer += b timer b {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            } timer += time.poll() timer time.poll() time.poll time System.out.println(name.poll() + " " + timer) System.out.println System.out System System.out name.poll() + " " + timer name.poll() + " " + timer name.poll() name.poll name " " timer String[] args args public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> name = new LinkedList<>();
        Queue<Integer> time = new LinkedList<>();
        int a = in.nextInt();
        int b = in.nextInt();
        int timer = 0;

        for (int i = 0; i < a; i++) {
            name.add(in.next());
            time.add(in.nextInt());
        }
        while (name.size() != 0) {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        }
    }
} public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> name = new LinkedList<>();
        Queue<Integer> time = new LinkedList<>();
        int a = in.nextInt();
        int b = in.nextInt();
        int timer = 0;

        for (int i = 0; i < a; i++) {
            name.add(in.next());
            time.add(in.nextInt());
        }
        while (name.size() != 0) {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        }
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> name = new LinkedList<>();
        Queue<Integer> time = new LinkedList<>();
        int a = in.nextInt();
        int b = in.nextInt();
        int timer = 0;

        for (int i = 0; i < a; i++) {
            name.add(in.next());
            time.add(in.nextInt());
        }
        while (name.size() != 0) {
            if (time.peek() - b > 0) {
                name.add(name.poll());
                time.add(time.poll() - b);
                timer += b;
            } else {
                timer += time.poll();
                System.out.println(name.poll() + " " + timer);
            }
        }
    }
}

