import java.util.Scanner;
import java.nio.*;

class Queue{
    private String name;
    private int time;

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

    public String getName(){
        return name;
    }

    public int getTime(){
        return time;
    }
}

class MyQueue{
    private Queue[] queue;
    private int head = 0;
    private int tail = 0;
    
    public MyQueue(int size){
        queue = new Queue[size + 1];
    }

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

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

    public void enqueue(String name, int time) throws Exception{
        if(isFull()){
            throw new Exception();
        }

        queue[tail] = new Queue(name, time);

        if(tail + 1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }

    public Queue dequeue() throws Exception{
        if(isEmpty()){
            throw new Exception();
        }
        Queue x = queue[head];
        if(head + 1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }

    public int min(int a, int b){
        return a < b ? a : b;
    }
}

public class Main{
        public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();

        MyQueue queue = new MyQueue(n);

        String name;
        int time;
        for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        }
        
        int sum = 0;
        while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        }
    }
}

 import java.util.Scanner; Scanner java.util import java.nio.*; nio.* java class Queue{
    private String name;
    private int time;

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

    public String getName(){
        return name;
    }

    public int getTime(){
        return time;
    }
} Queue private String name; name private int time; time public Queue(String name, int time){
        this.name = name;
        this.time = time;
    } Queue {
        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 class MyQueue{
    private Queue[] queue;
    private int head = 0;
    private int tail = 0;
    
    public MyQueue(int size){
        queue = new Queue[size + 1];
    }

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

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

    public void enqueue(String name, int time) throws Exception{
        if(isFull()){
            throw new Exception();
        }

        queue[tail] = new Queue(name, time);

        if(tail + 1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }

    public Queue dequeue() throws Exception{
        if(isEmpty()){
            throw new Exception();
        }
        Queue x = queue[head];
        if(head + 1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }

    public int min(int a, int b){
        return a < b ? a : b;
    }
} MyQueue private Queue[] queue; queue private int head = 0; head 0 private int tail = 0; tail 0 public MyQueue(int size){
        queue = new Queue[size + 1];
    } MyQueue {
        queue = new Queue[size + 1];
    } queue = new Queue[size + 1] queue new Queue[size + 1] size + 1 size 1 int size size public boolean isEmpty(){
        return head == tail;
    } isEmpty {
        return head == tail;
    } return head == tail; head == tail head tail public boolean isFull(){
        return head == (tail + 1) % queue.length;
    } isFull {
        return head == (tail + 1) % queue.length;
    } return head == (tail + 1) % queue.length; head == (tail + 1) % queue.length head (tail + 1) % queue.length (tail + 1) tail 1 queue.length queue queue.length public void enqueue(String name, int time) throws Exception{
        if(isFull()){
            throw new Exception();
        }

        queue[tail] = new Queue(name, time);

        if(tail + 1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    } enqueue {
        if(isFull()){
            throw new Exception();
        }

        queue[tail] = new Queue(name, time);

        if(tail + 1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    } if(isFull()){
            throw new Exception();
        } isFull() isFull {
            throw new Exception();
        } throw new Exception(); new Exception() queue[tail] = new Queue(name, time) queue[tail] queue tail new Queue(name, time) if(tail + 1 == queue.length){
            tail = 0;
        }else{
            tail++;
        } tail + 1 == queue.length tail + 1 tail 1 queue.length queue queue.length {
            tail = 0;
        } tail = 0 tail 0 {
            tail++;
        } tail++ tail String name name int time time public Queue dequeue() throws Exception{
        if(isEmpty()){
            throw new Exception();
        }
        Queue x = queue[head];
        if(head + 1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    } dequeue {
        if(isEmpty()){
            throw new Exception();
        }
        Queue x = queue[head];
        if(head + 1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    } if(isEmpty()){
            throw new Exception();
        } isEmpty() isEmpty {
            throw new Exception();
        } throw new Exception(); new Exception() Queue x = queue[head]; x queue[head] queue head if(head + 1 == queue.length){
            head = 0;
        }else{
            head++;
        } head + 1 == queue.length head + 1 head 1 queue.length queue queue.length {
            head = 0;
        } head = 0 head 0 {
            head++;
        } head++ head return x; x public int min(int a, int b){
        return a < b ? a : b;
    } min {
        return a < b ? a : b;
    } return a < b ? a : b; a < b ? a : b a < b a b a b int a a int b b public class Main{
        public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();

        MyQueue queue = new MyQueue(n);

        String name;
        int time;
        for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        }
        
        int sum = 0;
        while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        }
    }
} Main public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();

        MyQueue queue = new MyQueue(n);

        String name;
        int time;
        for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        }
        
        int sum = 0;
        while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();

        MyQueue queue = new MyQueue(n);

        String name;
        int time;
        for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        }
        
        int sum = 0;
        while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc MyQueue queue = new MyQueue(n); queue new MyQueue(n) String name; name int time; time for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        } {
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        } name = sc.next() name sc.next() sc.next sc time = sc.nextInt() time sc.nextInt() sc.nextInt sc queue.enqueue(name, time) queue.enqueue queue name time int sum = 0; sum 0 while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        } Queue q1 = queue.dequeue(); q1 queue.dequeue() queue.dequeue queue if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            } q1.getTime() > q q1.getTime() q1.getTime q1 q {
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            } sum += q sum q queue.enqueue(q1.getName(), q1.getTime() - q) queue.enqueue queue q1.getName() q1.getName q1 q1.getTime() - q q1.getTime() q1.getTime q1 q {
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            } sum += q1.getTime() sum q1.getTime() q1.getTime q1 System.out.println(q1.getName() + " " + sum) System.out.println System.out System System.out q1.getName() + " " + sum q1.getName() + " " + sum q1.getName() q1.getName q1 " " sum String[] args args public class Main{
        public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();

        MyQueue queue = new MyQueue(n);

        String name;
        int time;
        for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        }
        
        int sum = 0;
        while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        }
    }
} public class Main{
        public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();

        MyQueue queue = new MyQueue(n);

        String name;
        int time;
        for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        }
        
        int sum = 0;
        while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        }
    }
} Main
import java.util.Scanner;
import java.nio.*;

class Queue{
    private String name;
    private int time;

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

    public String getName(){
        return name;
    }

    public int getTime(){
        return time;
    }
}

class MyQueue{
    private Queue[] queue;
    private int head = 0;
    private int tail = 0;
    
    public MyQueue(int size){
        queue = new Queue[size + 1];
    }

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

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

    public void enqueue(String name, int time) throws Exception{
        if(isFull()){
            throw new Exception();
        }

        queue[tail] = new Queue(name, time);

        if(tail + 1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }

    public Queue dequeue() throws Exception{
        if(isEmpty()){
            throw new Exception();
        }
        Queue x = queue[head];
        if(head + 1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }

    public int min(int a, int b){
        return a < b ? a : b;
    }
}

public class Main{
        public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();

        MyQueue queue = new MyQueue(n);

        String name;
        int time;
        for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        }
        
        int sum = 0;
        while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        }
    }
}


