import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

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

        String[] values = scanner.nextLine().split(" ");
        int n = Integer.parseInt(values[0]);
        int limit = Integer.parseInt(values[1]);

        Queue<Process> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        }

        int elapsedTime = 0;
        while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        }

    }

    private static class Process {
        String processName;
        int reamingTime;

        Process(String[] data) {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        }

    }
}
 import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {

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

        String[] values = scanner.nextLine().split(" ");
        int n = Integer.parseInt(values[0]);
        int limit = Integer.parseInt(values[1]);

        Queue<Process> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        }

        int elapsedTime = 0;
        while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        }

    }

    private static class Process {
        String processName;
        int reamingTime;

        Process(String[] data) {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        }

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

        String[] values = scanner.nextLine().split(" ");
        int n = Integer.parseInt(values[0]);
        int limit = Integer.parseInt(values[1]);

        Queue<Process> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        }

        int elapsedTime = 0;
        while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        }

    } main {
        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int n = Integer.parseInt(values[0]);
        int limit = Integer.parseInt(values[1]);

        Queue<Process> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        }

        int elapsedTime = 0;
        while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        }

    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] values = scanner.nextLine().split(" "); values scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int n = Integer.parseInt(values[0]); n Integer.parseInt(values[0]) Integer.parseInt Integer values[0] values 0 int limit = Integer.parseInt(values[1]); limit Integer.parseInt(values[1]) Integer.parseInt Integer values[1] values 1 Queue<Process> queue = new ArrayDeque<>(); queue new ArrayDeque<>() for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            queue.add(new Process(scanner.nextLine().split(" ")));
        } {
            queue.add(new Process(scanner.nextLine().split(" ")));
        } queue.add(new Process(scanner.nextLine().split(" "))) queue.add queue new Process(scanner.nextLine().split(" ")) int elapsedTime = 0; elapsedTime 0 while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        } Process process = queue.poll(); process queue.poll() queue.poll queue int processTime = Math.min(process.reamingTime, limit); processTime Math.min(process.reamingTime, limit) Math.min Math process.reamingTime process process.reamingTime limit process.reamingTime -= processTime process.reamingTime process process.reamingTime processTime elapsedTime += processTime elapsedTime processTime if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            } process.reamingTime == 0 process.reamingTime process process.reamingTime 0 {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } System.out.println(process.processName + " " + Integer.toString(elapsedTime)) System.out.println System.out System System.out process.processName + " " + Integer.toString(elapsedTime) process.processName + " " + Integer.toString(elapsedTime) process.processName process process.processName " " Integer.toString(elapsedTime) Integer.toString Integer elapsedTime {
                queue.add(process);
            } queue.add(process) queue.add queue process String[] args args private static class Process {
        String processName;
        int reamingTime;

        Process(String[] data) {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        }

    } Process String processName; processName int reamingTime; reamingTime Process(String[] data) {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        } Process {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        } processName = data[0] processName data[0] data 0 reamingTime = Integer.parseInt(data[1]) reamingTime Integer.parseInt(data[1]) Integer.parseInt Integer data[1] data 1 String[] data data public class Main {

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

        String[] values = scanner.nextLine().split(" ");
        int n = Integer.parseInt(values[0]);
        int limit = Integer.parseInt(values[1]);

        Queue<Process> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        }

        int elapsedTime = 0;
        while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        }

    }

    private static class Process {
        String processName;
        int reamingTime;

        Process(String[] data) {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        }

    }
} public class Main {

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

        String[] values = scanner.nextLine().split(" ");
        int n = Integer.parseInt(values[0]);
        int limit = Integer.parseInt(values[1]);

        Queue<Process> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        }

        int elapsedTime = 0;
        while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        }

    }

    private static class Process {
        String processName;
        int reamingTime;

        Process(String[] data) {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        }

    }
} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

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

        String[] values = scanner.nextLine().split(" ");
        int n = Integer.parseInt(values[0]);
        int limit = Integer.parseInt(values[1]);

        Queue<Process> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        }

        int elapsedTime = 0;
        while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        }

    }

    private static class Process {
        String processName;
        int reamingTime;

        Process(String[] data) {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        }

    }
}

