import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Process {
    String name;
    int time;

    Process(String s, int n) {
        name = s;
        time = n;
    }
}

// I want to use Generics but General type array T[] cannot define.
// add(i, elm) of List<T> shift elements to right.
// So I do not use Generics here.
class Queue {
    int size;
    Process[] buf;
    int head = 0;
    int tail = 0;

    Queue(int n) {
        size = n + 1;
        buf = new Process[size];
    }

    boolean isEmpty() {
        return head == tail;
    }

    boolean isFull() {
        return head == (tail + 1) % size;
    }

    void enqueue(Process x) {
        if (isFull()) {
            throw new IndexOutOfBoundsException("Queue is full");
        }

        buf[tail] = x;
        if ((tail + 1) == size) {
            tail = 0;
        } else {
            tail++;
        }
    }

    Process dequeue() {
        if (isEmpty()) {
            throw new IndexOutOfBoundsException("Queue is empty");
        }

        Process x = buf[head];
        if ((head + 1) == size) {
            head = 0;
        } else {
            head++;
        }

        return x;
    }
}

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Process {
    String name;
    int time;

    Process(String s, int n) {
        name = s;
        time = n;
    }
} Process String name; name int time; time Process(String s, int n) {
        name = s;
        time = n;
    } Process {
        name = s;
        time = n;
    } name = s name s time = n time n String s s int n n class Queue {
    int size;
    Process[] buf;
    int head = 0;
    int tail = 0;

    Queue(int n) {
        size = n + 1;
        buf = new Process[size];
    }

    boolean isEmpty() {
        return head == tail;
    }

    boolean isFull() {
        return head == (tail + 1) % size;
    }

    void enqueue(Process x) {
        if (isFull()) {
            throw new IndexOutOfBoundsException("Queue is full");
        }

        buf[tail] = x;
        if ((tail + 1) == size) {
            tail = 0;
        } else {
            tail++;
        }
    }

    Process dequeue() {
        if (isEmpty()) {
            throw new IndexOutOfBoundsException("Queue is empty");
        }

        Process x = buf[head];
        if ((head + 1) == size) {
            head = 0;
        } else {
            head++;
        }

        return x;
    }
} Queue int size; size Process[] buf; buf int head = 0; head 0 int tail = 0; tail 0 Queue(int n) {
        size = n + 1;
        buf = new Process[size];
    } Queue {
        size = n + 1;
        buf = new Process[size];
    } size = n + 1 size n + 1 n 1 buf = new Process[size] buf new Process[size] size int n n boolean isEmpty() {
        return head == tail;
    } isEmpty {
        return head == tail;
    } return head == tail; head == tail head tail boolean isFull() {
        return head == (tail + 1) % size;
    } isFull {
        return head == (tail + 1) % size;
    } return head == (tail + 1) % size; head == (tail + 1) % size head (tail + 1) % size (tail + 1) tail 1 size void enqueue(Process x) {
        if (isFull()) {
            throw new IndexOutOfBoundsException("Queue is full");
        }

        buf[tail] = x;
        if ((tail + 1) == size) {
            tail = 0;
        } else {
            tail++;
        }
    } enqueue {
        if (isFull()) {
            throw new IndexOutOfBoundsException("Queue is full");
        }

        buf[tail] = x;
        if ((tail + 1) == size) {
            tail = 0;
        } else {
            tail++;
        }
    } if (isFull()) {
            throw new IndexOutOfBoundsException("Queue is full");
        } isFull() isFull {
            throw new IndexOutOfBoundsException("Queue is full");
        } throw new IndexOutOfBoundsException("Queue is full"); new IndexOutOfBoundsException("Queue is full") buf[tail] = x buf[tail] buf tail x if ((tail + 1) == size) {
            tail = 0;
        } else {
            tail++;
        } (tail + 1) == size (tail + 1) tail 1 size {
            tail = 0;
        } tail = 0 tail 0 {
            tail++;
        } tail++ tail Process x x Process dequeue() {
        if (isEmpty()) {
            throw new IndexOutOfBoundsException("Queue is empty");
        }

        Process x = buf[head];
        if ((head + 1) == size) {
            head = 0;
        } else {
            head++;
        }

        return x;
    } dequeue {
        if (isEmpty()) {
            throw new IndexOutOfBoundsException("Queue is empty");
        }

        Process x = buf[head];
        if ((head + 1) == size) {
            head = 0;
        } else {
            head++;
        }

        return x;
    } if (isEmpty()) {
            throw new IndexOutOfBoundsException("Queue is empty");
        } isEmpty() isEmpty {
            throw new IndexOutOfBoundsException("Queue is empty");
        } throw new IndexOutOfBoundsException("Queue is empty"); new IndexOutOfBoundsException("Queue is empty") Process x = buf[head]; x buf[head] buf head if ((head + 1) == size) {
            head = 0;
        } else {
            head++;
        } (head + 1) == size (head + 1) head 1 size {
            head = 0;
        } head = 0 head 0 {
            head++;
        } head++ head return x; x public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} Main public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    } main {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    } try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } IOException e {
            e.printStackTrace();
        } e.printStackTrace() e.printStackTrace e {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)) BufferedReader in = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) String[] line = in.readLine().split(" "); line in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int n = Integer.parseInt(line[0]); n Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int q = Integer.parseInt(line[1]); q Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 Queue queue = new Queue(n); queue new Queue(n) for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            } {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            } line = in.readLine().split(" ") line in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " String name = line[0]; name line[0] line 0 int time = Integer.parseInt(line[1]); time Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 queue.enqueue(new Process(name, time)) queue.enqueue queue new Process(name, time) int currTime = 0; currTime 0 while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            } true {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            } if (queue.isEmpty()) break; queue.isEmpty() queue.isEmpty queue break; Process p = queue.dequeue(); p queue.dequeue() queue.dequeue queue if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                } p.time <= q p.time p p.time q {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } currTime += p.time currTime p.time p p.time System.out.println(p.name + " " + currTime) System.out.println System.out System System.out p.name + " " + currTime p.name + " " + currTime p.name p p.name " " currTime {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                } currTime += q currTime q p.time -= q p.time p p.time q queue.enqueue(p) queue.enqueue queue p String[] args args public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Process {
    String name;
    int time;

    Process(String s, int n) {
        name = s;
        time = n;
    }
}

// I want to use Generics but General type array T[] cannot define.
// add(i, elm) of List<T> shift elements to right.
// So I do not use Generics here.
class Queue {
    int size;
    Process[] buf;
    int head = 0;
    int tail = 0;

    Queue(int n) {
        size = n + 1;
        buf = new Process[size];
    }

    boolean isEmpty() {
        return head == tail;
    }

    boolean isFull() {
        return head == (tail + 1) % size;
    }

    void enqueue(Process x) {
        if (isFull()) {
            throw new IndexOutOfBoundsException("Queue is full");
        }

        buf[tail] = x;
        if ((tail + 1) == size) {
            tail = 0;
        } else {
            tail++;
        }
    }

    Process dequeue() {
        if (isEmpty()) {
            throw new IndexOutOfBoundsException("Queue is empty");
        }

        Process x = buf[head];
        if ((head + 1) == size) {
            head = 0;
        } else {
            head++;
        }

        return x;
    }
}

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] line = in.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int q = Integer.parseInt(line[1]);

            Queue queue = new Queue(n);
            for (int i = 0; i < n; i++) {
                line = in.readLine().split(" ");
                String name = line[0];
                int time = Integer.parseInt(line[1]);
                queue.enqueue(new Process(name, time));
            }

            int currTime = 0;
            while (true) {
                if (queue.isEmpty()) break;

                Process p = queue.dequeue();
                if (p.time <= q) {
                    currTime += p.time;
                    System.out.println(p.name + " " + currTime);
                } else {
                    currTime += q;
                    p.time -= q;
                    queue.enqueue(p);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
