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

class Tuple{
    String name;
    int time;
    Tuple(String name, int time){
        this.name = name;
        this.time = time;
    }
}

class myQueue{
    int size = 100000;
    Tuple[] data;
    int head;
    int tail;

    myQueue(){
        data = new Tuple[size];
        head = 0;
        tail = 0;
    }

    void enqueue(String n, int t){
        if(isFull()){
            System.err.println("queue is full");
            return;
        }
        data[tail] = new Tuple(n,t);
        tail = (tail + 1) % size;
    }

    Tuple dequeue(){
        if(isEmpty()){
            System.err.println("queue is empty");
            return null;
        }
        Tuple answer = data[head];
        head = (head + 1) % size;
        return answer;
    }
    
    boolean isFull(){
        return head == (tail + 1) % size;
    }

    boolean isEmpty(){
        return head == tail;
    }
}
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        
        myQueue mq = new myQueue();
        for(int i = 0; i < n; i++){
            String[] line = br.readLine().split(" ");
            mq.enqueue(line[0], Integer.parseInt(line[1]));
        }

        int now = 0;
        while(!mq.isEmpty()){
            Tuple process = mq.dequeue();
            if(process.time <= q){
                now += process.time;
                System.out.println(process.name + " " + now);
            }else{
                now += q;
                mq.enqueue(process.name, process.time - q);
            }
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Tuple{
    String name;
    int time;
    Tuple(String name, int time){
        this.name = name;
        this.time = time;
    }
} Tuple String name; name int time; time Tuple(String name, int time){
        this.name = name;
        this.time = time;
    } Tuple {
        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 myQueue{
    int size = 100000;
    Tuple[] data;
    int head;
    int tail;

    myQueue(){
        data = new Tuple[size];
        head = 0;
        tail = 0;
    }

    void enqueue(String n, int t){
        if(isFull()){
            System.err.println("queue is full");
            return;
        }
        data[tail] = new Tuple(n,t);
        tail = (tail + 1) % size;
    }

    Tuple dequeue(){
        if(isEmpty()){
            System.err.println("queue is empty");
            return null;
        }
        Tuple answer = data[head];
        head = (head + 1) % size;
        return answer;
    }
    
    boolean isFull(){
        return head == (tail + 1) % size;
    }

    boolean isEmpty(){
        return head == tail;
    }
} myQueue int size = 100000; size 100000 Tuple[] data; data int head; head int tail; tail myQueue(){
        data = new Tuple[size];
        head = 0;
        tail = 0;
    } myQueue {
        data = new Tuple[size];
        head = 0;
        tail = 0;
    } data = new Tuple[size] data new Tuple[size] size head = 0 head 0 tail = 0 tail 0 void enqueue(String n, int t){
        if(isFull()){
            System.err.println("queue is full");
            return;
        }
        data[tail] = new Tuple(n,t);
        tail = (tail + 1) % size;
    } enqueue {
        if(isFull()){
            System.err.println("queue is full");
            return;
        }
        data[tail] = new Tuple(n,t);
        tail = (tail + 1) % size;
    } if(isFull()){
            System.err.println("queue is full");
            return;
        } isFull() isFull {
            System.err.println("queue is full");
            return;
        } System.err.println("queue is full") System.err.println System.err System System.err "queue is full" return; data[tail] = new Tuple(n,t) data[tail] data tail new Tuple(n,t) tail = (tail + 1) % size tail (tail + 1) % size (tail + 1) tail 1 size String n n int t t Tuple dequeue(){
        if(isEmpty()){
            System.err.println("queue is empty");
            return null;
        }
        Tuple answer = data[head];
        head = (head + 1) % size;
        return answer;
    } dequeue {
        if(isEmpty()){
            System.err.println("queue is empty");
            return null;
        }
        Tuple answer = data[head];
        head = (head + 1) % size;
        return answer;
    } if(isEmpty()){
            System.err.println("queue is empty");
            return null;
        } isEmpty() isEmpty {
            System.err.println("queue is empty");
            return null;
        } System.err.println("queue is empty") System.err.println System.err System System.err "queue is empty" return null; null Tuple answer = data[head]; answer data[head] data head head = (head + 1) % size head (head + 1) % size (head + 1) head 1 size return answer; answer 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 boolean isEmpty(){
        return head == tail;
    } isEmpty {
        return head == tail;
    } return head == tail; head == tail head tail class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        
        myQueue mq = new myQueue();
        for(int i = 0; i < n; i++){
            String[] line = br.readLine().split(" ");
            mq.enqueue(line[0], Integer.parseInt(line[1]));
        }

        int now = 0;
        while(!mq.isEmpty()){
            Tuple process = mq.dequeue();
            if(process.time <= q){
                now += process.time;
                System.out.println(process.name + " " + now);
            }else{
                now += q;
                mq.enqueue(process.name, process.time - q);
            }
        }
    }
} Main public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        
        myQueue mq = new myQueue();
        for(int i = 0; i < n; i++){
            String[] line = br.readLine().split(" ");
            mq.enqueue(line[0], Integer.parseInt(line[1]));
        }

        int now = 0;
        while(!mq.isEmpty()){
            Tuple process = mq.dequeue();
            if(process.time <= q){
                now += process.time;
                System.out.println(process.name + " " + now);
            }else{
                now += q;
                mq.enqueue(process.name, process.time - q);
            }
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        
        myQueue mq = new myQueue();
        for(int i = 0; i < n; i++){
            String[] line = br.readLine().split(" ");
            mq.enqueue(line[0], Integer.parseInt(line[1]));
        }

        int now = 0;
        while(!mq.isEmpty()){
            Tuple process = mq.dequeue();
            if(process.time <= q){
                now += process.time;
                System.out.println(process.name + " " + now);
            }else{
                now += q;
                mq.enqueue(process.name, process.time - q);
            }
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(input[0]); n Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 int q = Integer.parseInt(input[1]); q Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 myQueue mq = new myQueue(); mq new myQueue() for(int i = 0; i < n; i++){
            String[] line = br.readLine().split(" ");
            mq.enqueue(line[0], Integer.parseInt(line[1]));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String[] line = br.readLine().split(" ");
            mq.enqueue(line[0], Integer.parseInt(line[1]));
        } {
            String[] line = br.readLine().split(" ");
            mq.enqueue(line[0], Integer.parseInt(line[1]));
        } String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " mq.enqueue(line[0], Integer.parseInt(line[1])) mq.enqueue mq line[0] line 0 Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 int now = 0; now 0 while(!mq.isEmpty()){
            Tuple process = mq.dequeue();
            if(process.time <= q){
                now += process.time;
                System.out.println(process.name + " " + now);
            }else{
                now += q;
                mq.enqueue(process.name, process.time - q);
            }
        } !mq.isEmpty() mq.isEmpty() mq.isEmpty mq {
            Tuple process = mq.dequeue();
            if(process.time <= q){
                now += process.time;
                System.out.println(process.name + " " + now);
            }else{
                now += q;
                mq.enqueue(process.name, process.time - q);
            }
        } Tuple process = mq.dequeue(); process mq.dequeue() mq.dequeue mq if(process.time <= q){
                now += process.time;
                System.out.println(process.name + " " + now);
            }else{
                now += q;
                mq.enqueue(process.name, process.time - q);
            } process.time <= q process.time process process.time q {
                now += process.time;
                System.out.println(process.name + " " + now);
            } now += process.time now process.time process process.time System.out.println(process.name + " " + now) System.out.println System.out System System.out process.name + " " + now process.name + " " + now process.name process process.name " " now {
                now += q;
                mq.enqueue(process.name, process.time - q);
            } now += q now q mq.enqueue(process.name, process.time - q) mq.enqueue mq process.name process process.name process.time - q process.time process process.time q String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Tuple{
    String name;
    int time;
    Tuple(String name, int time){
        this.name = name;
        this.time = time;
    }
}

class myQueue{
    int size = 100000;
    Tuple[] data;
    int head;
    int tail;

    myQueue(){
        data = new Tuple[size];
        head = 0;
        tail = 0;
    }

    void enqueue(String n, int t){
        if(isFull()){
            System.err.println("queue is full");
            return;
        }
        data[tail] = new Tuple(n,t);
        tail = (tail + 1) % size;
    }

    Tuple dequeue(){
        if(isEmpty()){
            System.err.println("queue is empty");
            return null;
        }
        Tuple answer = data[head];
        head = (head + 1) % size;
        return answer;
    }
    
    boolean isFull(){
        return head == (tail + 1) % size;
    }

    boolean isEmpty(){
        return head == tail;
    }
}
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        
        myQueue mq = new myQueue();
        for(int i = 0; i < n; i++){
            String[] line = br.readLine().split(" ");
            mq.enqueue(line[0], Integer.parseInt(line[1]));
        }

        int now = 0;
        while(!mq.isEmpty()){
            Tuple process = mq.dequeue();
            if(process.time <= q){
                now += process.time;
                System.out.println(process.name + " " + now);
            }else{
                now += q;
                mq.enqueue(process.name, process.time - q);
            }
        }
    }
}
