import java.util.Scanner;

public class Main {

    public Main() {
    }

    private Scanner sc;

    public static void main(String[] args) {
        new Main().solve();
    }

    private void solve() {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        }

    }
}

class MyQueue {
    private int top;
    private int tail;
    private Object[] arr;

    public MyQueue() {
        top = 0;
        tail = -1;
        arr = new Object[1000000];
    }

    public void enqueue(Object o) {
        tail++;
        arr[tail] = o;
    }

    public Object dequeue() {
        Object r = arr[top];
        top++;
        return r;
    }

    public boolean isEmpty() {
        return top > tail;
    }
}

class Query {
    String name;
    int time;

    public Query(String name, int time) {
        super();
        this.name = name;
        this.time = time;
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public Main() {
    }

    private Scanner sc;

    public static void main(String[] args) {
        new Main().solve();
    }

    private void solve() {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        }

    }
} Main private Scanner sc; sc public Main() {
    } Main {
    } public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args private void solve() {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        }

    } solve {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        }

    } 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(); queue new MyQueue() for (int i = 0; i < n; i++) {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        } {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        } Query qry = new Query(sc.next(), sc.nextInt()); qry new Query(sc.next(), sc.nextInt()) queue.enqueue(qry) queue.enqueue queue qry int sum = 0; sum 0 while (!queue.isEmpty()) {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        } Query now = (Query) queue.dequeue(); now (Query) queue.dequeue() queue.dequeue queue if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            } now.time <= q now.time now now.time q {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } sum += now.time sum now.time now now.time System.out.println(now.name + " " + sum) System.out.println System.out System System.out now.name + " " + sum now.name + " " + sum now.name now now.name " " sum {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            } now.time -= q now.time now now.time q sum += q sum q queue.enqueue(now) queue.enqueue queue now class MyQueue {
    private int top;
    private int tail;
    private Object[] arr;

    public MyQueue() {
        top = 0;
        tail = -1;
        arr = new Object[1000000];
    }

    public void enqueue(Object o) {
        tail++;
        arr[tail] = o;
    }

    public Object dequeue() {
        Object r = arr[top];
        top++;
        return r;
    }

    public boolean isEmpty() {
        return top > tail;
    }
} MyQueue private int top; top private int tail; tail private Object[] arr; arr public MyQueue() {
        top = 0;
        tail = -1;
        arr = new Object[1000000];
    } MyQueue {
        top = 0;
        tail = -1;
        arr = new Object[1000000];
    } top = 0 top 0 tail = -1 tail -1 1 arr = new Object[1000000] arr new Object[1000000] 1000000 public void enqueue(Object o) {
        tail++;
        arr[tail] = o;
    } enqueue {
        tail++;
        arr[tail] = o;
    } tail++ tail arr[tail] = o arr[tail] arr tail o Object o o public Object dequeue() {
        Object r = arr[top];
        top++;
        return r;
    } dequeue {
        Object r = arr[top];
        top++;
        return r;
    } Object r = arr[top]; r arr[top] arr top top++ top return r; r public boolean isEmpty() {
        return top > tail;
    } isEmpty {
        return top > tail;
    } return top > tail; top > tail top tail class Query {
    String name;
    int time;

    public Query(String name, int time) {
        super();
        this.name = name;
        this.time = time;
    }
} Query String name; name int time; time public Query(String name, int time) {
        super();
        this.name = name;
        this.time = time;
    } Query {
        super();
        this.name = name;
        this.time = time;
    } super() super 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 class Main {

    public Main() {
    }

    private Scanner sc;

    public static void main(String[] args) {
        new Main().solve();
    }

    private void solve() {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        }

    }
} public class Main {

    public Main() {
    }

    private Scanner sc;

    public static void main(String[] args) {
        new Main().solve();
    }

    private void solve() {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        }

    }
} Main
import java.util.Scanner;

public class Main {

    public Main() {
    }

    private Scanner sc;

    public static void main(String[] args) {
        new Main().solve();
    }

    private void solve() {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        MyQueue queue = new MyQueue();
        for (int i = 0; i < n; i++) {
            Query qry = new Query(sc.next(), sc.nextInt());
            queue.enqueue(qry);
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            Query now = (Query) queue.dequeue();
            if (now.time <= q) {
                sum += now.time;
                System.out.println(now.name + " " + sum);
            } else {
                now.time -= q;
                sum += q;
                queue.enqueue(now);
            }
        }

    }
}

class MyQueue {
    private int top;
    private int tail;
    private Object[] arr;

    public MyQueue() {
        top = 0;
        tail = -1;
        arr = new Object[1000000];
    }

    public void enqueue(Object o) {
        tail++;
        arr[tail] = o;
    }

    public Object dequeue() {
        Object r = arr[top];
        top++;
        return r;
    }

    public boolean isEmpty() {
        return top > tail;
    }
}

class Query {
    String name;
    int time;

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