
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {


    private Scanner sc;

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

    private void solve() {
        sc = new Scanner(System.in);
        java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>();
        int n = sc.nextInt();
        int q = sc.nextInt();

        for (int i = 0; i < n; i++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        }
    }
}

class q1_3 {
    String name;
    int time;

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

} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Scanner; Scanner java.util public class Main {


    private Scanner sc;

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

    private void solve() {
        sc = new Scanner(System.in);
        java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>();
        int n = sc.nextInt();
        int q = sc.nextInt();

        for (int i = 0; i < n; i++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        }
    }
} Main private Scanner sc; sc 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);
        java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>();
        int n = sc.nextInt();
        int q = sc.nextInt();

        for (int i = 0; i < n; i++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        }
    } solve {
        sc = new Scanner(System.in);
        java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>();
        int n = sc.nextInt();
        int q = sc.nextInt();

        for (int i = 0; i < n; i++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        }
    } sc = new Scanner(System.in) sc new Scanner(System.in) java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>(); queue new ArrayDeque<q1_3>() 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++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        } {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        } queue.offer(new q1_3(sc.next(), sc.nextInt())) queue.offer queue new q1_3(sc.next(), sc.nextInt()) int sum = 0; sum 0 while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        } q1_3 now = queue.poll(); now queue.poll() queue.poll queue int d = Math.min(q, now.time); d Math.min(q, now.time) Math.min Math q now.time now now.time now.time -= d now.time now now.time d sum += d sum d if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            } now.time > 0 now.time now now.time 0 {
                queue.offer(now);
            } queue.offer(now) queue.offer queue now {

                System.out.println(now.name + " " + sum);
            } 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 class q1_3 {
    String name;
    int time;

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

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


    private Scanner sc;

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

    private void solve() {
        sc = new Scanner(System.in);
        java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>();
        int n = sc.nextInt();
        int q = sc.nextInt();

        for (int i = 0; i < n; i++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        }
    }
} public class Main {


    private Scanner sc;

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

    private void solve() {
        sc = new Scanner(System.in);
        java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>();
        int n = sc.nextInt();
        int q = sc.nextInt();

        for (int i = 0; i < n; i++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        }
    }
} Main

import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {


    private Scanner sc;

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

    private void solve() {
        sc = new Scanner(System.in);
        java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>();
        int n = sc.nextInt();
        int q = sc.nextInt();

        for (int i = 0; i < n; i++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        }
    }
}

class q1_3 {
    String name;
    int time;

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

}