import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] l = br.readLine().split(" ");
        int n = Integer.parseInt(l[0]);
        int q = Integer.parseInt(l[1]);
        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        }

        int allTime = 0;

        while (queue.size() > 0) {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        }
    }
}

class Process {

    private String name;

    private int time;

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

    public String getName() {
        return name;
    }

    public int getTime() {
        return time;
    }

    public void reduceTime(int dt) {
        time -= dt;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] l = br.readLine().split(" ");
        int n = Integer.parseInt(l[0]);
        int q = Integer.parseInt(l[1]);
        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        }

        int allTime = 0;

        while (queue.size() > 0) {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] l = br.readLine().split(" ");
        int n = Integer.parseInt(l[0]);
        int q = Integer.parseInt(l[1]);
        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        }

        int allTime = 0;

        while (queue.size() > 0) {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] l = br.readLine().split(" ");
        int n = Integer.parseInt(l[0]);
        int q = Integer.parseInt(l[1]);
        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        }

        int allTime = 0;

        while (queue.size() > 0) {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] l = br.readLine().split(" "); l br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(l[0]); n Integer.parseInt(l[0]) Integer.parseInt Integer l[0] l 0 int q = Integer.parseInt(l[1]); q Integer.parseInt(l[1]) Integer.parseInt Integer l[1] l 1 Queue<Process> queue = new LinkedList<>(); queue new LinkedList<>() for (int i = 0; i < n; i++) {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        } {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        } l = br.readLine().split(" ") l br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " String name = l[0]; name l[0] l 0 int time = Integer.parseInt(l[1]); time Integer.parseInt(l[1]) Integer.parseInt Integer l[1] l 1 Process process = new Process(name, time); process new Process(name, time) queue.offer(process) queue.offer queue process int allTime = 0; allTime 0 while (queue.size() > 0) {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        } queue.size() > 0 queue.size() queue.size queue 0 {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        } Process process = queue.poll(); process queue.poll() queue.poll queue int time = process.getTime(); time process.getTime() process.getTime process if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            } time <= q time q {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } allTime += time allTime time System.out.println(process.getName() + " " + allTime) System.out.println System.out System System.out process.getName() + " " + allTime process.getName() + " " + allTime process.getName() process.getName process " " allTime {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            } allTime += q allTime q process.reduceTime(q) process.reduceTime process q queue.offer(process) queue.offer queue process String[] args args class Process {

    private String name;

    private int time;

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

    public String getName() {
        return name;
    }

    public int getTime() {
        return time;
    }

    public void reduceTime(int dt) {
        time -= dt;
    }
} Process private String name; name private int time; time public Process(String name, int time) {
        this.name = name;
        this.time = time;
    } Process {
        this.name = name;
        this.time = time;
    } this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public String getName() {
        return name;
    } getName {
        return name;
    } return name; name public int getTime() {
        return time;
    } getTime {
        return time;
    } return time; time public void reduceTime(int dt) {
        time -= dt;
    } reduceTime {
        time -= dt;
    } time -= dt time dt int dt dt public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] l = br.readLine().split(" ");
        int n = Integer.parseInt(l[0]);
        int q = Integer.parseInt(l[1]);
        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        }

        int allTime = 0;

        while (queue.size() > 0) {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        }
    }
} public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] l = br.readLine().split(" ");
        int n = Integer.parseInt(l[0]);
        int q = Integer.parseInt(l[1]);
        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        }

        int allTime = 0;

        while (queue.size() > 0) {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] l = br.readLine().split(" ");
        int n = Integer.parseInt(l[0]);
        int q = Integer.parseInt(l[1]);
        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            l = br.readLine().split(" ");
            String name = l[0];
            int time = Integer.parseInt(l[1]);
            Process process = new Process(name, time);
            queue.offer(process);
        }

        int allTime = 0;

        while (queue.size() > 0) {
            Process process = queue.poll();
            int time = process.getTime();
            if (time <= q) {
                allTime += time;
                System.out.println(process.getName() + " " + allTime);
            } else {
                allTime += q;
                process.reduceTime(q);
                queue.offer(process);
            }
        }
    }
}

class Process {

    private String name;

    private int time;

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

    public String getName() {
        return name;
    }

    public int getTime() {
        return time;
    }

    public void reduceTime(int dt) {
        time -= dt;
    }
}