import java.util.Scanner;

public class Main {
    public static int MAX = 100001;
    public static class Task{
        String name;
        int t;
    }
    public static class MyQueue {
        int head, tail = 0;
        Task[] a = new Task[MAX];
        public boolean isFull(){
            return head == (tail + 1) % MAX;
        }
        public boolean isEmpty(){
            return head == tail;
        }
        public boolean enqueue(Task s){
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        }
        public Task dequeue(){
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        }
    }
    public static void startSchedule(MyQueue myQueue, int q, Task[] tasks){
        int countTime = 0;
        while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        }
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n,q;
        MyQueue myQueue = new MyQueue();
        n = scanner.nextInt();
        Task[] tasks = new Task[n];
        q = scanner.nextInt();
        for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        }
        startSchedule(myQueue, q, tasks);
    }
}
 import java.util.Scanner; Scanner java.util public class Main {
    public static int MAX = 100001;
    public static class Task{
        String name;
        int t;
    }
    public static class MyQueue {
        int head, tail = 0;
        Task[] a = new Task[MAX];
        public boolean isFull(){
            return head == (tail + 1) % MAX;
        }
        public boolean isEmpty(){
            return head == tail;
        }
        public boolean enqueue(Task s){
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        }
        public Task dequeue(){
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        }
    }
    public static void startSchedule(MyQueue myQueue, int q, Task[] tasks){
        int countTime = 0;
        while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        }
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n,q;
        MyQueue myQueue = new MyQueue();
        n = scanner.nextInt();
        Task[] tasks = new Task[n];
        q = scanner.nextInt();
        for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        }
        startSchedule(myQueue, q, tasks);
    }
} Main public static int MAX = 100001; MAX 100001 public static void startSchedule(MyQueue myQueue, int q, Task[] tasks){
        int countTime = 0;
        while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        }
    } startSchedule {
        int countTime = 0;
        while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        }
    } int countTime = 0; countTime 0 while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        } !myQueue.isEmpty() myQueue.isEmpty() myQueue.isEmpty myQueue {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        } Task task = myQueue.dequeue(); task myQueue.dequeue() myQueue.dequeue myQueue int value = task.t; value task.t task task.t if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            } !(value - q <= 0) (value - q <= 0) value - q value q 0 {
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            } myQueue.enqueue(task) myQueue.enqueue myQueue task task.t = value - q task.t task task.t value - q value q countTime += q countTime q continue; {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            } System.out.printf("%s %d\n",task.name, countTime + value) System.out.printf System.out System System.out "%s %d\n" task.name task task.name countTime + value countTime value countTime += value countTime value MyQueue myQueue myQueue int q q Task[] tasks tasks public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n,q;
        MyQueue myQueue = new MyQueue();
        n = scanner.nextInt();
        Task[] tasks = new Task[n];
        q = scanner.nextInt();
        for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        }
        startSchedule(myQueue, q, tasks);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n,q;
        MyQueue myQueue = new MyQueue();
        n = scanner.nextInt();
        Task[] tasks = new Task[n];
        q = scanner.nextInt();
        for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        }
        startSchedule(myQueue, q, tasks);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n n q; q MyQueue myQueue = new MyQueue(); myQueue new MyQueue() n = scanner.nextInt() n scanner.nextInt() scanner.nextInt scanner Task[] tasks = new Task[n]; tasks new Task[n] n q = scanner.nextInt() q scanner.nextInt() scanner.nextInt scanner for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        } {
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        } tasks[i] = new Task() tasks[i] tasks i new Task() tasks[i].name = scanner.next() tasks[i].name tasks[i] tasks i tasks[i].name scanner.next() scanner.next scanner tasks[i].t = scanner.nextInt() tasks[i].t tasks[i] tasks i tasks[i].t scanner.nextInt() scanner.nextInt scanner myQueue.enqueue(tasks[i]) myQueue.enqueue myQueue tasks[i] tasks i startSchedule(myQueue, q, tasks) startSchedule myQueue q tasks String[] args args public static class Task{
        String name;
        int t;
    } Task String name; name int t; t public static class MyQueue {
        int head, tail = 0;
        Task[] a = new Task[MAX];
        public boolean isFull(){
            return head == (tail + 1) % MAX;
        }
        public boolean isEmpty(){
            return head == tail;
        }
        public boolean enqueue(Task s){
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        }
        public Task dequeue(){
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        }
    } MyQueue int head head tail = 0; tail 0 Task[] a = new Task[MAX]; a new Task[MAX] MAX public boolean isFull(){
            return head == (tail + 1) % MAX;
        } isFull {
            return head == (tail + 1) % MAX;
        } return head == (tail + 1) % MAX; head == (tail + 1) % MAX head (tail + 1) % MAX (tail + 1) tail 1 MAX public boolean isEmpty(){
            return head == tail;
        } isEmpty {
            return head == tail;
        } return head == tail; head == tail head tail public boolean enqueue(Task s){
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        } enqueue {
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        } if (isFull()) {
                throw new NullPointerException("queue is full");
            } isFull() isFull {
                throw new NullPointerException("queue is full");
            } throw new NullPointerException("queue is full"); new NullPointerException("queue is full") a[tail] = s a[tail] a tail s if (++tail == MAX) tail = 0; ++tail == MAX ++tail tail MAX tail = 0 tail 0 return true; true Task s s public Task dequeue(){
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        } dequeue {
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        } if (isEmpty()){
                throw new NullPointerException("queue is empty");
            } isEmpty() isEmpty {
                throw new NullPointerException("queue is empty");
            } throw new NullPointerException("queue is empty"); new NullPointerException("queue is empty") Task s = a[head]; s a[head] a head if (++head == MAX) head = 0; ++head == MAX ++head head MAX head = 0 head 0 return s; s public class Main {
    public static int MAX = 100001;
    public static class Task{
        String name;
        int t;
    }
    public static class MyQueue {
        int head, tail = 0;
        Task[] a = new Task[MAX];
        public boolean isFull(){
            return head == (tail + 1) % MAX;
        }
        public boolean isEmpty(){
            return head == tail;
        }
        public boolean enqueue(Task s){
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        }
        public Task dequeue(){
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        }
    }
    public static void startSchedule(MyQueue myQueue, int q, Task[] tasks){
        int countTime = 0;
        while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        }
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n,q;
        MyQueue myQueue = new MyQueue();
        n = scanner.nextInt();
        Task[] tasks = new Task[n];
        q = scanner.nextInt();
        for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        }
        startSchedule(myQueue, q, tasks);
    }
} public class Main {
    public static int MAX = 100001;
    public static class Task{
        String name;
        int t;
    }
    public static class MyQueue {
        int head, tail = 0;
        Task[] a = new Task[MAX];
        public boolean isFull(){
            return head == (tail + 1) % MAX;
        }
        public boolean isEmpty(){
            return head == tail;
        }
        public boolean enqueue(Task s){
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        }
        public Task dequeue(){
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        }
    }
    public static void startSchedule(MyQueue myQueue, int q, Task[] tasks){
        int countTime = 0;
        while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        }
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n,q;
        MyQueue myQueue = new MyQueue();
        n = scanner.nextInt();
        Task[] tasks = new Task[n];
        q = scanner.nextInt();
        for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        }
        startSchedule(myQueue, q, tasks);
    }
} Main
import java.util.Scanner;

public class Main {
    public static int MAX = 100001;
    public static class Task{
        String name;
        int t;
    }
    public static class MyQueue {
        int head, tail = 0;
        Task[] a = new Task[MAX];
        public boolean isFull(){
            return head == (tail + 1) % MAX;
        }
        public boolean isEmpty(){
            return head == tail;
        }
        public boolean enqueue(Task s){
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        }
        public Task dequeue(){
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        }
    }
    public static void startSchedule(MyQueue myQueue, int q, Task[] tasks){
        int countTime = 0;
        while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        }
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n,q;
        MyQueue myQueue = new MyQueue();
        n = scanner.nextInt();
        Task[] tasks = new Task[n];
        q = scanner.nextInt();
        for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        }
        startSchedule(myQueue, q, tasks);
    }
}

