import java.util.*;

class Task {
    String name;
    int time;
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Task> que = new ArrayDeque<>();

        for (int i = 0; i < n; i++) {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        }

        int time = 0;

        while(que.peek() != null) {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        }
        
        sc.close();
    }
}
 import java.util.*; util.* java class Task {
    String name;
    int time;
} Task String name; name int time; time public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Task> que = new ArrayDeque<>();

        for (int i = 0; i < n; i++) {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        }

        int time = 0;

        while(que.peek() != null) {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        }
        
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Task> que = new ArrayDeque<>();

        for (int i = 0; i < n; i++) {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        }

        int time = 0;

        while(que.peek() != null) {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        }
        
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Task> que = new ArrayDeque<>();

        for (int i = 0; i < n; i++) {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        }

        int time = 0;

        while(que.peek() != null) {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        }
        
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int quantum = sc.nextInt(); quantum sc.nextInt() sc.nextInt sc Queue<Task> que = new ArrayDeque<>(); que new ArrayDeque<>() for (int i = 0; i < n; i++) {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        } {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        } Task task = new Task(); task new Task() task.name = sc.next() task.name task task.name sc.next() sc.next sc task.time = sc.nextInt() task.time task task.time sc.nextInt() sc.nextInt sc que.offer(task) que.offer que task int time = 0; time 0 while(que.peek() != null) {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        } que.peek() != null que.peek() que.peek que null {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        } Task task = que.poll(); task que.poll() que.poll que if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            } task.time > quantum task.time task task.time quantum {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } time += quantum time quantum task.time -= quantum task.time task task.time quantum que.offer(task) que.offer que task {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            } time += task.time time task.time task task.time String output = String.format("%s %d", task.name, time); output String.format("%s %d", task.name, time) String.format String "%s %d" task.name task task.name time System.out.println(output) System.out.println System.out System System.out output sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Task> que = new ArrayDeque<>();

        for (int i = 0; i < n; i++) {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        }

        int time = 0;

        while(que.peek() != null) {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        }
        
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Task> que = new ArrayDeque<>();

        for (int i = 0; i < n; i++) {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        }

        int time = 0;

        while(que.peek() != null) {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        }
        
        sc.close();
    }
} Main
import java.util.*;

class Task {
    String name;
    int time;
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Task> que = new ArrayDeque<>();

        for (int i = 0; i < n; i++) {
            Task task = new Task();
            task.name = sc.next();
            task.time = sc.nextInt();
            que.offer(task);
        }

        int time = 0;

        while(que.peek() != null) {
            Task task = que.poll();
            if (task.time > quantum) {
                time += quantum;
                task.time -= quantum;
                que.offer(task);
            } else {
                time += task.time;
                String output = String.format("%s %d", task.name, time);
                System.out.println(output);
            }
        }
        
        sc.close();
    }
}

