import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        ArrayList<String> name = new ArrayList<>();
        ArrayList<Integer> time = new ArrayList<>();

        int numberProc = inp.nextInt();
        int quantity = inp.nextInt();

        for (int i = 0; i < numberProc; i++) {
            name.add(inp.next());
            time.add(inp.nextInt());
        }

        int finalCount = 0;

        int finalplaceholder = 0;

        String[] finalName = new String[100005];
        int[] finalTime = new int[100005];

        while (!name.isEmpty()) {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        }

        for (int i = 0; i < finalName.length; i++) {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        }
    }
}
 import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        ArrayList<String> name = new ArrayList<>();
        ArrayList<Integer> time = new ArrayList<>();

        int numberProc = inp.nextInt();
        int quantity = inp.nextInt();

        for (int i = 0; i < numberProc; i++) {
            name.add(inp.next());
            time.add(inp.nextInt());
        }

        int finalCount = 0;

        int finalplaceholder = 0;

        String[] finalName = new String[100005];
        int[] finalTime = new int[100005];

        while (!name.isEmpty()) {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        }

        for (int i = 0; i < finalName.length; i++) {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        ArrayList<String> name = new ArrayList<>();
        ArrayList<Integer> time = new ArrayList<>();

        int numberProc = inp.nextInt();
        int quantity = inp.nextInt();

        for (int i = 0; i < numberProc; i++) {
            name.add(inp.next());
            time.add(inp.nextInt());
        }

        int finalCount = 0;

        int finalplaceholder = 0;

        String[] finalName = new String[100005];
        int[] finalTime = new int[100005];

        while (!name.isEmpty()) {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        }

        for (int i = 0; i < finalName.length; i++) {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        }
    } main {
        Scanner inp = new Scanner(System.in);

        ArrayList<String> name = new ArrayList<>();
        ArrayList<Integer> time = new ArrayList<>();

        int numberProc = inp.nextInt();
        int quantity = inp.nextInt();

        for (int i = 0; i < numberProc; i++) {
            name.add(inp.next());
            time.add(inp.nextInt());
        }

        int finalCount = 0;

        int finalplaceholder = 0;

        String[] finalName = new String[100005];
        int[] finalTime = new int[100005];

        while (!name.isEmpty()) {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        }

        for (int i = 0; i < finalName.length; i++) {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        }
    } Scanner inp = new Scanner(System.in); inp new Scanner(System.in) ArrayList<String> name = new ArrayList<>(); name new ArrayList<>() ArrayList<Integer> time = new ArrayList<>(); time new ArrayList<>() int numberProc = inp.nextInt(); numberProc inp.nextInt() inp.nextInt inp int quantity = inp.nextInt(); quantity inp.nextInt() inp.nextInt inp for (int i = 0; i < numberProc; i++) {
            name.add(inp.next());
            time.add(inp.nextInt());
        } int i = 0; int i = 0; i 0 i < numberProc i numberProc i++ i++ i {
            name.add(inp.next());
            time.add(inp.nextInt());
        } {
            name.add(inp.next());
            time.add(inp.nextInt());
        } name.add(inp.next()) name.add name inp.next() inp.next inp time.add(inp.nextInt()) time.add time inp.nextInt() inp.nextInt inp int finalCount = 0; finalCount 0 int finalplaceholder = 0; finalplaceholder 0 String[] finalName = new String[100005]; finalName new String[100005] 100005 int[] finalTime = new int[100005]; finalTime new int[100005] 100005 while (!name.isEmpty()) {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        } !name.isEmpty() name.isEmpty() name.isEmpty name {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        } String tempholdName = name.get(0); tempholdName name.get(0) name.get name 0 int tempholdTime = time.get(0); tempholdTime time.get(0) time.get time 0 name.remove(0) name.remove name 0 time.remove(0) time.remove time 0 if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            } tempholdTime <= quantity tempholdTime quantity {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } finalCount += tempholdTime finalCount tempholdTime finalName[finalplaceholder] = tempholdName finalName[finalplaceholder] finalName finalplaceholder tempholdName finalTime[finalplaceholder] = finalCount finalTime[finalplaceholder] finalTime finalplaceholder finalCount finalplaceholder++ finalplaceholder {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            } name.add(name.size(), tempholdName) name.add name name.size() name.size name tempholdName time.add(time.size(), (tempholdTime-quantity)) time.add time time.size() time.size time (tempholdTime-quantity) tempholdTime quantity finalCount += quantity finalCount quantity for (int i = 0; i < finalName.length; i++) {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        } int i = 0; int i = 0; i 0 i < finalName.length i finalName.length finalName finalName.length i++ i++ i {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        } {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        } if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            } finalName[i] != null finalName[i] finalName i null {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } System.out.println(finalName[i] + " " + finalTime[i]) System.out.println System.out System System.out finalName[i] + " " + finalTime[i] finalName[i] + " " + finalTime[i] finalName[i] finalName i " " finalTime[i] finalTime i {
                break;
            } break; String[] args args public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        ArrayList<String> name = new ArrayList<>();
        ArrayList<Integer> time = new ArrayList<>();

        int numberProc = inp.nextInt();
        int quantity = inp.nextInt();

        for (int i = 0; i < numberProc; i++) {
            name.add(inp.next());
            time.add(inp.nextInt());
        }

        int finalCount = 0;

        int finalplaceholder = 0;

        String[] finalName = new String[100005];
        int[] finalTime = new int[100005];

        while (!name.isEmpty()) {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        }

        for (int i = 0; i < finalName.length; i++) {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        ArrayList<String> name = new ArrayList<>();
        ArrayList<Integer> time = new ArrayList<>();

        int numberProc = inp.nextInt();
        int quantity = inp.nextInt();

        for (int i = 0; i < numberProc; i++) {
            name.add(inp.next());
            time.add(inp.nextInt());
        }

        int finalCount = 0;

        int finalplaceholder = 0;

        String[] finalName = new String[100005];
        int[] finalTime = new int[100005];

        while (!name.isEmpty()) {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        }

        for (int i = 0; i < finalName.length; i++) {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        ArrayList<String> name = new ArrayList<>();
        ArrayList<Integer> time = new ArrayList<>();

        int numberProc = inp.nextInt();
        int quantity = inp.nextInt();

        for (int i = 0; i < numberProc; i++) {
            name.add(inp.next());
            time.add(inp.nextInt());
        }

        int finalCount = 0;

        int finalplaceholder = 0;

        String[] finalName = new String[100005];
        int[] finalTime = new int[100005];

        while (!name.isEmpty()) {
            String tempholdName = name.get(0);
            int tempholdTime = time.get(0);

            name.remove(0);
            time.remove(0);

            if (tempholdTime <= quantity) {
                finalCount += tempholdTime;

                finalName[finalplaceholder] = tempholdName;
                finalTime[finalplaceholder] = finalCount;

                finalplaceholder++;
            } else {
                name.add(name.size(), tempholdName);
                time.add(time.size(), (tempholdTime-quantity));

                finalCount += quantity;
            }
        }

        for (int i = 0; i < finalName.length; i++) {
            if (finalName[i] != null) {
                System.out.println(finalName[i] + " " + finalTime[i]);
            } else {
                break;
            }
        }
    }
}

