import java.util.ArrayList;
import java.util.Scanner;

class Process {
    String name;
    int time;
    int finishTime;

    Process(String name, int time, int finishTime) {
        this.name = name;
        this.time = time;
        this.finishTime = finishTime;
    }
}

class Main {

    int size;
    int quantum;

    public void go() {
        Scanner sc = new Scanner(System.in);
        this.size = sc.nextInt();
        this.quantum = sc.nextInt();
        ArrayList<Process> list = new ArrayList<Process>();
        ArrayList<Process> finishList = new ArrayList<Process>();
        for (int i = 0; i < this.size; i++) {
            list.add(new Process(sc.next(), sc.nextInt(), 0));
        }

        int time = 0;
        while (!list.isEmpty()) {
            Process currentProcess = list.get(0);
            // finish
            if (currentProcess.time <= this.quantum) {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } else {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            }
            list.remove(0);
        }
        for (Process process : finishList) {
            System.out.println(process.name + " " + process.finishTime);
        }
    }

    public static void main(String[] args) {
        Main cui = new Main();
        cui.go();
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Process {
    String name;
    int time;
    int finishTime;

    Process(String name, int time, int finishTime) {
        this.name = name;
        this.time = time;
        this.finishTime = finishTime;
    }
} Process String name; name int time; time int finishTime; finishTime Process(String name, int time, int finishTime) {
        this.name = name;
        this.time = time;
        this.finishTime = finishTime;
    } Process {
        this.name = name;
        this.time = time;
        this.finishTime = finishTime;
    } this.name = name this.name this this.name name this.time = time this.time this this.time time this.finishTime = finishTime this.finishTime this this.finishTime finishTime String name name int time time int finishTime finishTime class Main {

    int size;
    int quantum;

    public void go() {
        Scanner sc = new Scanner(System.in);
        this.size = sc.nextInt();
        this.quantum = sc.nextInt();
        ArrayList<Process> list = new ArrayList<Process>();
        ArrayList<Process> finishList = new ArrayList<Process>();
        for (int i = 0; i < this.size; i++) {
            list.add(new Process(sc.next(), sc.nextInt(), 0));
        }

        int time = 0;
        while (!list.isEmpty()) {
            Process currentProcess = list.get(0);
            // finish
            if (currentProcess.time <= this.quantum) {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } else {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            }
            list.remove(0);
        }
        for (Process process : finishList) {
            System.out.println(process.name + " " + process.finishTime);
        }
    }

    public static void main(String[] args) {
        Main cui = new Main();
        cui.go();
    }
} Main int size; size int quantum; quantum public void go() {
        Scanner sc = new Scanner(System.in);
        this.size = sc.nextInt();
        this.quantum = sc.nextInt();
        ArrayList<Process> list = new ArrayList<Process>();
        ArrayList<Process> finishList = new ArrayList<Process>();
        for (int i = 0; i < this.size; i++) {
            list.add(new Process(sc.next(), sc.nextInt(), 0));
        }

        int time = 0;
        while (!list.isEmpty()) {
            Process currentProcess = list.get(0);
            // finish
            if (currentProcess.time <= this.quantum) {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } else {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            }
            list.remove(0);
        }
        for (Process process : finishList) {
            System.out.println(process.name + " " + process.finishTime);
        }
    } go {
        Scanner sc = new Scanner(System.in);
        this.size = sc.nextInt();
        this.quantum = sc.nextInt();
        ArrayList<Process> list = new ArrayList<Process>();
        ArrayList<Process> finishList = new ArrayList<Process>();
        for (int i = 0; i < this.size; i++) {
            list.add(new Process(sc.next(), sc.nextInt(), 0));
        }

        int time = 0;
        while (!list.isEmpty()) {
            Process currentProcess = list.get(0);
            // finish
            if (currentProcess.time <= this.quantum) {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } else {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            }
            list.remove(0);
        }
        for (Process process : finishList) {
            System.out.println(process.name + " " + process.finishTime);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) this.size = sc.nextInt() this.size this this.size sc.nextInt() sc.nextInt sc this.quantum = sc.nextInt() this.quantum this this.quantum sc.nextInt() sc.nextInt sc ArrayList<Process> list = new ArrayList<Process>(); list new ArrayList<Process>() ArrayList<Process> finishList = new ArrayList<Process>(); finishList new ArrayList<Process>() for (int i = 0; i < this.size; i++) {
            list.add(new Process(sc.next(), sc.nextInt(), 0));
        } int i = 0; int i = 0; i 0 i < this.size i this.size this this.size i++ i++ i {
            list.add(new Process(sc.next(), sc.nextInt(), 0));
        } {
            list.add(new Process(sc.next(), sc.nextInt(), 0));
        } list.add(new Process(sc.next(), sc.nextInt(), 0)) list.add list new Process(sc.next(), sc.nextInt(), 0) int time = 0; time 0 while (!list.isEmpty()) {
            Process currentProcess = list.get(0);
            // finish
            if (currentProcess.time <= this.quantum) {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } else {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            }
            list.remove(0);
        } !list.isEmpty() list.isEmpty() list.isEmpty list {
            Process currentProcess = list.get(0);
            // finish
            if (currentProcess.time <= this.quantum) {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } else {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            }
            list.remove(0);
        } Process currentProcess = list.get(0); currentProcess list.get(0) list.get list 0 if (currentProcess.time <= this.quantum) {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } else {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            } currentProcess.time <= this.quantum currentProcess.time currentProcess currentProcess.time this.quantum this this.quantum {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } currentProcess.finishTime = time + currentProcess.time currentProcess.finishTime currentProcess currentProcess.finishTime time + currentProcess.time time currentProcess.time currentProcess currentProcess.time finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime)) finishList.add finishList new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime) time += currentProcess.time time currentProcess.time currentProcess currentProcess.time {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            } currentProcess.time -= this.quantum currentProcess.time currentProcess currentProcess.time this.quantum this this.quantum list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime)) list.add list new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime) time += this.quantum time this.quantum this this.quantum list.remove(0) list.remove list 0 for (Process process : finishList) {
            System.out.println(process.name + " " + process.finishTime);
        } Process process finishList {
            System.out.println(process.name + " " + process.finishTime);
        } {
            System.out.println(process.name + " " + process.finishTime);
        } System.out.println(process.name + " " + process.finishTime) System.out.println System.out System System.out process.name + " " + process.finishTime process.name + " " + process.finishTime process.name process process.name " " process.finishTime process process.finishTime public static void main(String[] args) {
        Main cui = new Main();
        cui.go();
    } main {
        Main cui = new Main();
        cui.go();
    } Main cui = new Main(); cui new Main() cui.go() cui.go cui String[] args args
import java.util.ArrayList;
import java.util.Scanner;

class Process {
    String name;
    int time;
    int finishTime;

    Process(String name, int time, int finishTime) {
        this.name = name;
        this.time = time;
        this.finishTime = finishTime;
    }
}

class Main {

    int size;
    int quantum;

    public void go() {
        Scanner sc = new Scanner(System.in);
        this.size = sc.nextInt();
        this.quantum = sc.nextInt();
        ArrayList<Process> list = new ArrayList<Process>();
        ArrayList<Process> finishList = new ArrayList<Process>();
        for (int i = 0; i < this.size; i++) {
            list.add(new Process(sc.next(), sc.nextInt(), 0));
        }

        int time = 0;
        while (!list.isEmpty()) {
            Process currentProcess = list.get(0);
            // finish
            if (currentProcess.time <= this.quantum) {
                currentProcess.finishTime = time + currentProcess.time;
                finishList.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += currentProcess.time;
            } else {
                currentProcess.time -= this.quantum;
                list.add(new Process(currentProcess.name, currentProcess.time, currentProcess.finishTime));
                time += this.quantum;
            }
            list.remove(0);
        }
        for (Process process : finishList) {
            System.out.println(process.name + " " + process.finishTime);
        }
    }

    public static void main(String[] args) {
        Main cui = new Main();
        cui.go();
    }
}
