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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int quantime = Integer.parseInt(nq[1]);

        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        }

        int sum = 0;
        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        }
    }

    private static class MyQueue {
        private Process[] processes;
        private int head;
        private int tail;

        public MyQueue() {
            this.processes = new Process[100000];
            this.head = 0;
            this.tail = 0;
        }

        public void enqueue(Process process) {
            this.processes[this.tail] = process;
            if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            }
        }

        public Process dequeue() {
            if (isEmpty()) throw new RuntimeException();

            int head = this.head;
            if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            }
            return this.processes[head];
        }

        public boolean isEmpty() {
            return this.tail == this.head;
        }
    }

    private static class Process {
        private String name;
        private int restTime;
        private int quantime;

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

        public int work() {
            if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            }
            int consume = restTime;
            restTime = 0;
            return consume;
        }

        public boolean isDone() {
            return this.restTime == 0;
        }

        public String getName() {
            return name;
        }
    }
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int quantime = Integer.parseInt(nq[1]);

        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        }

        int sum = 0;
        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        }
    }

    private static class MyQueue {
        private Process[] processes;
        private int head;
        private int tail;

        public MyQueue() {
            this.processes = new Process[100000];
            this.head = 0;
            this.tail = 0;
        }

        public void enqueue(Process process) {
            this.processes[this.tail] = process;
            if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            }
        }

        public Process dequeue() {
            if (isEmpty()) throw new RuntimeException();

            int head = this.head;
            if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            }
            return this.processes[head];
        }

        public boolean isEmpty() {
            return this.tail == this.head;
        }
    }

    private static class Process {
        private String name;
        private int restTime;
        private int quantime;

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

        public int work() {
            if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            }
            int consume = restTime;
            restTime = 0;
            return consume;
        }

        public boolean isDone() {
            return this.restTime == 0;
        }

        public String getName() {
            return name;
        }
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int quantime = Integer.parseInt(nq[1]);

        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        }

        int sum = 0;
        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int quantime = Integer.parseInt(nq[1]);

        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        }

        int sum = 0;
        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] nq = br.readLine().split(" "); nq br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(nq[0]); n Integer.parseInt(nq[0]) Integer.parseInt Integer nq[0] nq 0 int quantime = Integer.parseInt(nq[1]); quantime Integer.parseInt(nq[1]) Integer.parseInt Integer nq[1] nq 1 MyQueue queue = new MyQueue(); queue new MyQueue() for (int i = 0; i < n; i++) {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        } {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        } String[] processStr = br.readLine().split(" "); processStr br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime)) queue.enqueue queue new Process(processStr[0], Integer.parseInt(processStr[1]), quantime) int sum = 0; sum 0 while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        } Process process = queue.dequeue(); process queue.dequeue() queue.dequeue queue int consume = process.work(); consume process.work() process.work process sum += consume sum consume if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            } process.isDone() process.isDone process {
                System.out.println(process.getName() + " " + sum);
            } System.out.println(process.getName() + " " + sum) System.out.println System.out System System.out process.getName() + " " + sum process.getName() + " " + sum process.getName() process.getName process " " sum {
                queue.enqueue(process);
            } queue.enqueue(process) queue.enqueue queue process String[] args args private static class MyQueue {
        private Process[] processes;
        private int head;
        private int tail;

        public MyQueue() {
            this.processes = new Process[100000];
            this.head = 0;
            this.tail = 0;
        }

        public void enqueue(Process process) {
            this.processes[this.tail] = process;
            if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            }
        }

        public Process dequeue() {
            if (isEmpty()) throw new RuntimeException();

            int head = this.head;
            if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            }
            return this.processes[head];
        }

        public boolean isEmpty() {
            return this.tail == this.head;
        }
    } MyQueue private Process[] processes; processes private int head; head private int tail; tail public MyQueue() {
            this.processes = new Process[100000];
            this.head = 0;
            this.tail = 0;
        } MyQueue {
            this.processes = new Process[100000];
            this.head = 0;
            this.tail = 0;
        } this.processes = new Process[100000] this.processes this this.processes new Process[100000] 100000 this.head = 0 this.head this this.head 0 this.tail = 0 this.tail this this.tail 0 public void enqueue(Process process) {
            this.processes[this.tail] = process;
            if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            }
        } enqueue {
            this.processes[this.tail] = process;
            if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            }
        } this.processes[this.tail] = process this.processes[this.tail] this.processes this this.processes this.tail this this.tail process if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            } this.tail + 1 >= 100000 this.tail + 1 this.tail this this.tail 1 100000 {
                this.tail = 0;
            } this.tail = 0 this.tail this this.tail 0 {
                this.tail++;
            } this.tail++ this.tail this this.tail Process process process public Process dequeue() {
            if (isEmpty()) throw new RuntimeException();

            int head = this.head;
            if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            }
            return this.processes[head];
        } dequeue {
            if (isEmpty()) throw new RuntimeException();

            int head = this.head;
            if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            }
            return this.processes[head];
        } if (isEmpty()) throw new RuntimeException(); isEmpty() isEmpty throw new RuntimeException(); new RuntimeException() int head = this.head; head this.head this this.head if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            } head + 1 >= 100000 head + 1 head 1 100000 {
                this.head = 0;
            } this.head = 0 this.head this this.head 0 {
                this.head++;
            } this.head++ this.head this this.head return this.processes[head]; this.processes[head] this.processes this this.processes head public boolean isEmpty() {
            return this.tail == this.head;
        } isEmpty {
            return this.tail == this.head;
        } return this.tail == this.head; this.tail == this.head this.tail this this.tail this.head this this.head private static class Process {
        private String name;
        private int restTime;
        private int quantime;

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

        public int work() {
            if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            }
            int consume = restTime;
            restTime = 0;
            return consume;
        }

        public boolean isDone() {
            return this.restTime == 0;
        }

        public String getName() {
            return name;
        }
    } Process private String name; name private int restTime; restTime private int quantime; quantime public Process(String name, int restTime, int quantime) {
            this.name = name;
            this.restTime = restTime;
            this.quantime = quantime;
        } Process {
            this.name = name;
            this.restTime = restTime;
            this.quantime = quantime;
        } this.name = name this.name this this.name name this.restTime = restTime this.restTime this this.restTime restTime this.quantime = quantime this.quantime this this.quantime quantime String name name int restTime restTime int quantime quantime public int work() {
            if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            }
            int consume = restTime;
            restTime = 0;
            return consume;
        } work {
            if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            }
            int consume = restTime;
            restTime = 0;
            return consume;
        } if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            } quantime <= restTime quantime restTime {
                restTime -= quantime;
                return quantime;
            } restTime -= quantime restTime quantime return quantime; quantime int consume = restTime; consume restTime restTime = 0 restTime 0 return consume; consume public boolean isDone() {
            return this.restTime == 0;
        } isDone {
            return this.restTime == 0;
        } return this.restTime == 0; this.restTime == 0 this.restTime this this.restTime 0 public String getName() {
            return name;
        } getName {
            return name;
        } return name; name public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int quantime = Integer.parseInt(nq[1]);

        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        }

        int sum = 0;
        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        }
    }

    private static class MyQueue {
        private Process[] processes;
        private int head;
        private int tail;

        public MyQueue() {
            this.processes = new Process[100000];
            this.head = 0;
            this.tail = 0;
        }

        public void enqueue(Process process) {
            this.processes[this.tail] = process;
            if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            }
        }

        public Process dequeue() {
            if (isEmpty()) throw new RuntimeException();

            int head = this.head;
            if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            }
            return this.processes[head];
        }

        public boolean isEmpty() {
            return this.tail == this.head;
        }
    }

    private static class Process {
        private String name;
        private int restTime;
        private int quantime;

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

        public int work() {
            if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            }
            int consume = restTime;
            restTime = 0;
            return consume;
        }

        public boolean isDone() {
            return this.restTime == 0;
        }

        public String getName() {
            return name;
        }
    }
} public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int quantime = Integer.parseInt(nq[1]);

        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        }

        int sum = 0;
        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        }
    }

    private static class MyQueue {
        private Process[] processes;
        private int head;
        private int tail;

        public MyQueue() {
            this.processes = new Process[100000];
            this.head = 0;
            this.tail = 0;
        }

        public void enqueue(Process process) {
            this.processes[this.tail] = process;
            if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            }
        }

        public Process dequeue() {
            if (isEmpty()) throw new RuntimeException();

            int head = this.head;
            if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            }
            return this.processes[head];
        }

        public boolean isEmpty() {
            return this.tail == this.head;
        }
    }

    private static class Process {
        private String name;
        private int restTime;
        private int quantime;

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

        public int work() {
            if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            }
            int consume = restTime;
            restTime = 0;
            return consume;
        }

        public boolean isDone() {
            return this.restTime == 0;
        }

        public String getName() {
            return name;
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int quantime = Integer.parseInt(nq[1]);

        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            String[] processStr = br.readLine().split(" ");
            queue.enqueue(new Process(processStr[0], Integer.parseInt(processStr[1]), quantime));
        }

        int sum = 0;
        while (!queue.isEmpty()) {
            Process process = queue.dequeue();
            int consume = process.work();
            sum += consume;
            if (process.isDone()) {
                System.out.println(process.getName() + " " + sum);
            } else {
                queue.enqueue(process);
            }
        }
    }

    private static class MyQueue {
        private Process[] processes;
        private int head;
        private int tail;

        public MyQueue() {
            this.processes = new Process[100000];
            this.head = 0;
            this.tail = 0;
        }

        public void enqueue(Process process) {
            this.processes[this.tail] = process;
            if (this.tail + 1 >= 100000) {
                this.tail = 0;
            } else {
                this.tail++;
            }
        }

        public Process dequeue() {
            if (isEmpty()) throw new RuntimeException();

            int head = this.head;
            if (head + 1 >= 100000) {
                this.head = 0;
            } else {
                this.head++;
            }
            return this.processes[head];
        }

        public boolean isEmpty() {
            return this.tail == this.head;
        }
    }

    private static class Process {
        private String name;
        private int restTime;
        private int quantime;

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

        public int work() {
            if (quantime <= restTime) {
                restTime -= quantime;
                return quantime;
            }
            int consume = restTime;
            restTime = 0;
            return consume;
        }

        public boolean isDone() {
            return this.restTime == 0;
        }

        public String getName() {
            return name;
        }
    }
}

