import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.util.LinkedList;

public class Main{

    static int n, q;

    static class Process {
        String pid;
        int task;
        int end;

        public Process(String pid, int task) {
            this.pid = pid;
            this.task = task;
        }

        public void setEnd(int end) {
            this.end = end;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        n = Integer.parseInt(st[0]);
        q = Integer.parseInt(st[1]);
        LinkedList<Process> Queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        }

        int ePosition = 0;
        Process[] endProcess = new Process[n];
        int time = 0;
        while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        }

        for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        }
        bw.flush();
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.BufferedWriter; BufferedWriter java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.OutputStreamWriter; OutputStreamWriter java.io import java.io.IOException; IOException java.io import java.util.LinkedList; LinkedList java.util public class Main{

    static int n, q;

    static class Process {
        String pid;
        int task;
        int end;

        public Process(String pid, int task) {
            this.pid = pid;
            this.task = task;
        }

        public void setEnd(int end) {
            this.end = end;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        n = Integer.parseInt(st[0]);
        q = Integer.parseInt(st[1]);
        LinkedList<Process> Queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        }

        int ePosition = 0;
        Process[] endProcess = new Process[n];
        int time = 0;
        while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        }

        for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        }
        bw.flush();
    }
} Main static int n n q; q public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        n = Integer.parseInt(st[0]);
        q = Integer.parseInt(st[1]);
        LinkedList<Process> Queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        }

        int ePosition = 0;
        Process[] endProcess = new Process[n];
        int time = 0;
        while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        }

        for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        }
        bw.flush();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        n = Integer.parseInt(st[0]);
        q = Integer.parseInt(st[1]);
        LinkedList<Process> Queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        }

        int ePosition = 0;
        Process[] endProcess = new Process[n];
        int time = 0;
        while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        }

        for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        }
        bw.flush();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); bw new BufferedWriter(new OutputStreamWriter(System.out)) String[] st = br.readLine().split(" "); st br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n = Integer.parseInt(st[0]) n Integer.parseInt(st[0]) Integer.parseInt Integer st[0] st 0 q = Integer.parseInt(st[1]) q Integer.parseInt(st[1]) Integer.parseInt Integer st[1] st 1 LinkedList<Process> Queue = new LinkedList<>(); Queue new LinkedList<>() for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        } {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        } st = br.readLine().split(" ") st br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " String pid = st[0]; pid st[0] st 0 int task = Integer.parseInt(st[1]); task Integer.parseInt(st[1]) Integer.parseInt Integer st[1] st 1 Process p = new Process(pid, task); p new Process(pid, task) Queue.add(p) Queue.add Queue p int ePosition = 0; ePosition 0 Process[] endProcess = new Process[n]; endProcess new Process[n] n int time = 0; time 0 while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        } !Queue.isEmpty() Queue.isEmpty() Queue.isEmpty Queue {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        } Process p = Queue.pollFirst(); p Queue.pollFirst() Queue.pollFirst Queue if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            } p.task < q p.task p p.task q {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } time += p.task time p.task p p.task p.end = time p.end p p.end time endProcess[ePosition++] = p endProcess[ePosition++] endProcess ePosition++ ePosition p if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            } p.task > q p.task p p.task q {
                p.task -= q;
                time += q;
                Queue.add(p);
            } p.task -= q p.task p p.task q time += q time q Queue.add(p) Queue.add Queue p {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            } time += q time q p.end = time p.end p p.end time endProcess[ePosition++] = p endProcess[ePosition++] endProcess ePosition++ ePosition p for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        } Process p endProcess {
            bw.append(p.pid + " " + p.end + "\n");
        } {
            bw.append(p.pid + " " + p.end + "\n");
        } bw.append(p.pid + " " + p.end + "\n") bw.append bw p.pid + " " + p.end + "\n" p.end p.pid + " " + p.end + "\n" p.pid p p.pid " " p.end p p.end "\n" bw.flush() bw.flush bw String[] args args static class Process {
        String pid;
        int task;
        int end;

        public Process(String pid, int task) {
            this.pid = pid;
            this.task = task;
        }

        public void setEnd(int end) {
            this.end = end;
        }
    } Process String pid; pid int task; task int end; end public Process(String pid, int task) {
            this.pid = pid;
            this.task = task;
        } Process {
            this.pid = pid;
            this.task = task;
        } this.pid = pid this.pid this this.pid pid this.task = task this.task this this.task task String pid pid int task task public void setEnd(int end) {
            this.end = end;
        } setEnd {
            this.end = end;
        } this.end = end this.end this this.end end int end end public class Main{

    static int n, q;

    static class Process {
        String pid;
        int task;
        int end;

        public Process(String pid, int task) {
            this.pid = pid;
            this.task = task;
        }

        public void setEnd(int end) {
            this.end = end;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        n = Integer.parseInt(st[0]);
        q = Integer.parseInt(st[1]);
        LinkedList<Process> Queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        }

        int ePosition = 0;
        Process[] endProcess = new Process[n];
        int time = 0;
        while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        }

        for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        }
        bw.flush();
    }
} public class Main{

    static int n, q;

    static class Process {
        String pid;
        int task;
        int end;

        public Process(String pid, int task) {
            this.pid = pid;
            this.task = task;
        }

        public void setEnd(int end) {
            this.end = end;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        n = Integer.parseInt(st[0]);
        q = Integer.parseInt(st[1]);
        LinkedList<Process> Queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        }

        int ePosition = 0;
        Process[] endProcess = new Process[n];
        int time = 0;
        while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        }

        for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        }
        bw.flush();
    }
} Main
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.util.LinkedList;

public class Main{

    static int n, q;

    static class Process {
        String pid;
        int task;
        int end;

        public Process(String pid, int task) {
            this.pid = pid;
            this.task = task;
        }

        public void setEnd(int end) {
            this.end = end;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        n = Integer.parseInt(st[0]);
        q = Integer.parseInt(st[1]);
        LinkedList<Process> Queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            String pid = st[0];
            int task = Integer.parseInt(st[1]);
            Process p = new Process(pid, task);
            Queue.add(p);
        }

        int ePosition = 0;
        Process[] endProcess = new Process[n];
        int time = 0;
        while (!Queue.isEmpty()) {
            Process p = Queue.pollFirst();
            if (p.task < q) {
                time += p.task;
                p.end = time;
                endProcess[ePosition++] = p;
            } else if (p.task > q) {
                p.task -= q;
                time += q;
                Queue.add(p);
            } else {
                time += q;
                p.end = time;
                endProcess[ePosition++] = p;
            }
        }

        for (Process p : endProcess) {
            bw.append(p.pid + " " + p.end + "\n");
        }
        bw.flush();
    }
}
