import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt(), ms = sc.nextInt();
        String[] name = new String[c];
        int[] time = new int[c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        int total = 0;
        while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        }
    }
} import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt(), ms = sc.nextInt();
        String[] name = new String[c];
        int[] time = new int[c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        int total = 0;
        while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt(), ms = sc.nextInt();
        String[] name = new String[c];
        int[] time = new int[c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        int total = 0;
        while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt(), ms = sc.nextInt();
        String[] name = new String[c];
        int[] time = new int[c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        int total = 0;
        while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int c = sc.nextInt() c sc.nextInt() sc.nextInt sc ms = sc.nextInt(); ms sc.nextInt() sc.nextInt sc String[] name = new String[c]; name new String[c] c int[] time = new int[c]; time new int[c] c Queue<Integer> queue = new LinkedList<>(); queue new LinkedList<>() for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        } int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        } {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        } name[i] = sc.next() name[i] name i sc.next() sc.next sc time[i] = sc.nextInt() time[i] time i sc.nextInt() sc.nextInt sc queue.add(i) queue.add queue i int total = 0; total 0 while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        } int i = queue.remove(); i queue.remove() queue.remove queue if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            } time[i] > ms time[i] time i ms {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } time[i] -= ms time[i] time i ms total += ms total ms queue.add(i) queue.add queue i {
                total += time[i];
                System.out.println(name[i] + " " + total);
            } total += time[i] total time[i] time i System.out.println(name[i] + " " + total) System.out.println System.out System System.out name[i] + " " + total name[i] + " " + total name[i] name i " " total String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt(), ms = sc.nextInt();
        String[] name = new String[c];
        int[] time = new int[c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        int total = 0;
        while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        }
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt(), ms = sc.nextInt();
        String[] name = new String[c];
        int[] time = new int[c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        int total = 0;
        while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        }
    }
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt(), ms = sc.nextInt();
        String[] name = new String[c];
        int[] time = new int[c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        int total = 0;
        while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        }
    }
}