import java.util.Scanner;

class Task{
    String name;
    int time;
}

public class Main {

    static final int len = 100005;
    static Task[] num = new Task[len];

    static int head = 0;
    static int tail = 0;

    // ??????????????????????????????
    public static void enqueue(Task task){
        num[tail] = task;
        tail = (tail+1) % len;
    }

    // ??????????????????????????????
    public static Task dequeue(){
        Task temp = num[head];
        head = (head+1) % len;
        return temp;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        }

        tail = n;

        int sum = 0;

        //????????????????????¶????????¬??????????????????
        while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        }
    }

} import java.util.Scanner; Scanner java.util class Task{
    String name;
    int time;
} Task String name; name int time; time public class Main {

    static final int len = 100005;
    static Task[] num = new Task[len];

    static int head = 0;
    static int tail = 0;

    // ??????????????????????????????
    public static void enqueue(Task task){
        num[tail] = task;
        tail = (tail+1) % len;
    }

    // ??????????????????????????????
    public static Task dequeue(){
        Task temp = num[head];
        head = (head+1) % len;
        return temp;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        }

        tail = n;

        int sum = 0;

        //????????????????????¶????????¬??????????????????
        while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        }
    }

} Main static final int len = 100005; len 100005 static Task[] num = new Task[len]; num new Task[len] len static int head = 0; head 0 static int tail = 0; tail 0 // ??????????????????????????????
    public static void enqueue(Task task){
        num[tail] = task;
        tail = (tail+1) % len;
    } enqueue {
        num[tail] = task;
        tail = (tail+1) % len;
    } num[tail] = task num[tail] num tail task tail = (tail+1) % len tail (tail+1) % len (tail+1) tail 1 len Task task task // ??????????????????????????????
    public static Task dequeue(){
        Task temp = num[head];
        head = (head+1) % len;
        return temp;
    } dequeue {
        Task temp = num[head];
        head = (head+1) % len;
        return temp;
    } Task temp = num[head]; temp num[head] num head head = (head+1) % len head (head+1) % len (head+1) head 1 len return temp; temp public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        }

        tail = n;

        int sum = 0;

        //????????????????????¶????????¬??????????????????
        while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        }
    } main {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        }

        tail = n;

        int sum = 0;

        //????????????????????¶????????¬??????????????????
        while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        }
    } 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 for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        } {
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        } Task temp = new Task(); temp new Task() temp.name = sc.next() temp.name temp temp.name sc.next() sc.next sc temp.time = sc.nextInt() temp.time temp temp.time sc.nextInt() sc.nextInt sc enqueue(temp) enqueue temp tail = n tail n int sum = 0; sum 0 while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        } head != tail head tail {
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        } Task temp = dequeue(); temp dequeue() dequeue if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            } temp.time <= q temp.time temp temp.time q {
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            } sum += temp.time sum temp.time temp temp.time System.out.println(temp.name + " " + sum) System.out.println System.out System System.out temp.name + " " + sum temp.name + " " + sum temp.name temp temp.name " " sum {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            } temp.time -= q temp.time temp temp.time q enqueue(temp) enqueue temp sum += q sum q String[] args args public class Main {

    static final int len = 100005;
    static Task[] num = new Task[len];

    static int head = 0;
    static int tail = 0;

    // ??????????????????????????????
    public static void enqueue(Task task){
        num[tail] = task;
        tail = (tail+1) % len;
    }

    // ??????????????????????????????
    public static Task dequeue(){
        Task temp = num[head];
        head = (head+1) % len;
        return temp;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        }

        tail = n;

        int sum = 0;

        //????????????????????¶????????¬??????????????????
        while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        }
    }

} public class Main {

    static final int len = 100005;
    static Task[] num = new Task[len];

    static int head = 0;
    static int tail = 0;

    // ??????????????????????????????
    public static void enqueue(Task task){
        num[tail] = task;
        tail = (tail+1) % len;
    }

    // ??????????????????????????????
    public static Task dequeue(){
        Task temp = num[head];
        head = (head+1) % len;
        return temp;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        }

        tail = n;

        int sum = 0;

        //????????????????????¶????????¬??????????????????
        while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        }
    }

} Main
import java.util.Scanner;

class Task{
    String name;
    int time;
}

public class Main {

    static final int len = 100005;
    static Task[] num = new Task[len];

    static int head = 0;
    static int tail = 0;

    // ??????????????????????????????
    public static void enqueue(Task task){
        num[tail] = task;
        tail = (tail+1) % len;
    }

    // ??????????????????????????????
    public static Task dequeue(){
        Task temp = num[head];
        head = (head+1) % len;
        return temp;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        }

        tail = n;

        int sum = 0;

        //????????????????????¶????????¬??????????????????
        while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        }
    }

}