import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String[] line = new String[n];
        Queue tasks = new Queue();
        in.nextLine();
        for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        }
        int costTime = 0;
        int totalTime = 0;
        while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        }
    }
}

class Task {
    public String name;
    public int time;

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

class Queue {
    public int head;
    public int tail;
    private Task[] queue;
    private int len = 1000001;

    public Queue() {
        this.head = this.tail = 0;
        this.queue = new Task[this.len];
    }

    public boolean isFull() {
        return (this.head == (this.tail + 1) % (this.len));
    }

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

    public void enqueue(Task task) throws Exception {
        if (isFull()) {
            throw (new Exception("上溢出"));
        }
        this.queue[this.tail] = task;
        if (this.tail + 1 == this.len) {
            this.tail = 0;
        } else {
            this.tail++;
        }
    }

    public Task dequeue() throws Exception {
        if (isEmpty()) {
            throw (new Exception("下溢出"));
        }
        Task task = this.queue[this.head];
        if (this.head + 1 == this.len) {
            this.head = 0;
        } else {
            this.head++;
        }
        return task;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String[] line = new String[n];
        Queue tasks = new Queue();
        in.nextLine();
        for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        }
        int costTime = 0;
        int totalTime = 0;
        while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String[] line = new String[n];
        Queue tasks = new Queue();
        in.nextLine();
        for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        }
        int costTime = 0;
        int totalTime = 0;
        while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        }
    } main {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String[] line = new String[n];
        Queue tasks = new Queue();
        in.nextLine();
        for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        }
        int costTime = 0;
        int totalTime = 0;
        while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        }
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int q = in.nextInt(); q in.nextInt() in.nextInt in String[] line = new String[n]; line new String[n] n Queue tasks = new Queue(); tasks new Queue() in.nextLine() in.nextLine in for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        } {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        } line[i] = in.nextLine() line[i] line i in.nextLine() in.nextLine in tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1]))) tasks.enqueue tasks new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])) int costTime = 0; costTime 0 int totalTime = 0; totalTime 0 while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        } tasks.head != tasks.tail tasks.head tasks tasks.head tasks.tail tasks tasks.tail {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        } Task current = tasks.dequeue(); current tasks.dequeue() tasks.dequeue tasks costTime = Math.min(q, current.time) costTime Math.min(q, current.time) Math.min Math q current.time current current.time current.time -= costTime current.time current current.time costTime totalTime += costTime totalTime costTime if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            } current.time > 0 current.time current current.time 0 {
                tasks.enqueue(current);
            } tasks.enqueue(current) tasks.enqueue tasks current {
                System.out.println(current.name + " " + totalTime);
            } System.out.println(current.name + " " + totalTime) System.out.println System.out System System.out current.name + " " + totalTime current.name + " " + totalTime current.name current current.name " " totalTime String[] args args class Task {
    public String name;
    public int time;

    public Task(String name, int time) {
        this.name = name;
        this.time = time;
    }
} Task public String name; name public int time; time public Task(String name, int time) {
        this.name = name;
        this.time = time;
    } Task {
        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 class Queue {
    public int head;
    public int tail;
    private Task[] queue;
    private int len = 1000001;

    public Queue() {
        this.head = this.tail = 0;
        this.queue = new Task[this.len];
    }

    public boolean isFull() {
        return (this.head == (this.tail + 1) % (this.len));
    }

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

    public void enqueue(Task task) throws Exception {
        if (isFull()) {
            throw (new Exception("上溢出"));
        }
        this.queue[this.tail] = task;
        if (this.tail + 1 == this.len) {
            this.tail = 0;
        } else {
            this.tail++;
        }
    }

    public Task dequeue() throws Exception {
        if (isEmpty()) {
            throw (new Exception("下溢出"));
        }
        Task task = this.queue[this.head];
        if (this.head + 1 == this.len) {
            this.head = 0;
        } else {
            this.head++;
        }
        return task;
    }
} Queue public int head; head public int tail; tail private Task[] queue; queue private int len = 1000001; len 1000001 public Queue() {
        this.head = this.tail = 0;
        this.queue = new Task[this.len];
    } Queue {
        this.head = this.tail = 0;
        this.queue = new Task[this.len];
    } this.head = this.tail = 0 this.head this this.head this.tail = 0 this.tail this this.tail 0 this.queue = new Task[this.len] this.queue this this.queue new Task[this.len] this.len this this.len public boolean isFull() {
        return (this.head == (this.tail + 1) % (this.len));
    } isFull {
        return (this.head == (this.tail + 1) % (this.len));
    } return (this.head == (this.tail + 1) % (this.len)); (this.head == (this.tail + 1) % (this.len)) this.head this this.head (this.tail + 1) % (this.len) (this.tail + 1) this.tail this this.tail 1 (this.len) this this.len public boolean isEmpty() {
        return (this.head == this.tail);
    } isEmpty {
        return (this.head == this.tail);
    } return (this.head == this.tail); (this.head == this.tail) this.head this this.head this.tail this this.tail public void enqueue(Task task) throws Exception {
        if (isFull()) {
            throw (new Exception("上溢出"));
        }
        this.queue[this.tail] = task;
        if (this.tail + 1 == this.len) {
            this.tail = 0;
        } else {
            this.tail++;
        }
    } enqueue {
        if (isFull()) {
            throw (new Exception("上溢出"));
        }
        this.queue[this.tail] = task;
        if (this.tail + 1 == this.len) {
            this.tail = 0;
        } else {
            this.tail++;
        }
    } if (isFull()) {
            throw (new Exception("上溢出"));
        } isFull() isFull {
            throw (new Exception("上溢出"));
        } throw (new Exception("上溢出")); (new Exception("上溢出")) this.queue[this.tail] = task this.queue[this.tail] this.queue this this.queue this.tail this this.tail task if (this.tail + 1 == this.len) {
            this.tail = 0;
        } else {
            this.tail++;
        } this.tail + 1 == this.len this.tail + 1 this.tail this this.tail 1 this.len this this.len {
            this.tail = 0;
        } this.tail = 0 this.tail this this.tail 0 {
            this.tail++;
        } this.tail++ this.tail this this.tail Task task task public Task dequeue() throws Exception {
        if (isEmpty()) {
            throw (new Exception("下溢出"));
        }
        Task task = this.queue[this.head];
        if (this.head + 1 == this.len) {
            this.head = 0;
        } else {
            this.head++;
        }
        return task;
    } dequeue {
        if (isEmpty()) {
            throw (new Exception("下溢出"));
        }
        Task task = this.queue[this.head];
        if (this.head + 1 == this.len) {
            this.head = 0;
        } else {
            this.head++;
        }
        return task;
    } if (isEmpty()) {
            throw (new Exception("下溢出"));
        } isEmpty() isEmpty {
            throw (new Exception("下溢出"));
        } throw (new Exception("下溢出")); (new Exception("下溢出")) Task task = this.queue[this.head]; task this.queue[this.head] this.queue this this.queue this.head this this.head if (this.head + 1 == this.len) {
            this.head = 0;
        } else {
            this.head++;
        } this.head + 1 == this.len this.head + 1 this.head this this.head 1 this.len this this.len {
            this.head = 0;
        } this.head = 0 this.head this this.head 0 {
            this.head++;
        } this.head++ this.head this this.head return task; task public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String[] line = new String[n];
        Queue tasks = new Queue();
        in.nextLine();
        for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        }
        int costTime = 0;
        int totalTime = 0;
        while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String[] line = new String[n];
        Queue tasks = new Queue();
        in.nextLine();
        for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        }
        int costTime = 0;
        int totalTime = 0;
        while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String[] line = new String[n];
        Queue tasks = new Queue();
        in.nextLine();
        for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        }
        int costTime = 0;
        int totalTime = 0;
        while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        }
    }
}

class Task {
    public String name;
    public int time;

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

class Queue {
    public int head;
    public int tail;
    private Task[] queue;
    private int len = 1000001;

    public Queue() {
        this.head = this.tail = 0;
        this.queue = new Task[this.len];
    }

    public boolean isFull() {
        return (this.head == (this.tail + 1) % (this.len));
    }

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

    public void enqueue(Task task) throws Exception {
        if (isFull()) {
            throw (new Exception("上溢出"));
        }
        this.queue[this.tail] = task;
        if (this.tail + 1 == this.len) {
            this.tail = 0;
        } else {
            this.tail++;
        }
    }

    public Task dequeue() throws Exception {
        if (isEmpty()) {
            throw (new Exception("下溢出"));
        }
        Task task = this.queue[this.head];
        if (this.head + 1 == this.len) {
            this.head = 0;
        } else {
            this.head++;
        }
        return task;
    }
}
