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

// You cant store primitive types in queue?

public class Main{
    public static void main(String[] args) {
        Queue<String> q = new LinkedList<>();

        Scanner input1 = new Scanner(System.in);
        int length = input1.nextInt();
        int QUANTUM = input1.nextInt();
        int totalTime=0;
        int result; // This is the time of each item
        String name;

        input1.nextLine();
        // Takes all the inputs and put into the queue
        for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        }

        while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        }
    }
}
 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) {
        Queue<String> q = new LinkedList<>();

        Scanner input1 = new Scanner(System.in);
        int length = input1.nextInt();
        int QUANTUM = input1.nextInt();
        int totalTime=0;
        int result; // This is the time of each item
        String name;

        input1.nextLine();
        // Takes all the inputs and put into the queue
        for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        }

        while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        }
    }
} Main public static void main(String[] args) {
        Queue<String> q = new LinkedList<>();

        Scanner input1 = new Scanner(System.in);
        int length = input1.nextInt();
        int QUANTUM = input1.nextInt();
        int totalTime=0;
        int result; // This is the time of each item
        String name;

        input1.nextLine();
        // Takes all the inputs and put into the queue
        for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        }

        while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        }
    } main {
        Queue<String> q = new LinkedList<>();

        Scanner input1 = new Scanner(System.in);
        int length = input1.nextInt();
        int QUANTUM = input1.nextInt();
        int totalTime=0;
        int result; // This is the time of each item
        String name;

        input1.nextLine();
        // Takes all the inputs and put into the queue
        for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        }

        while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        }
    } Queue<String> q = new LinkedList<>(); q new LinkedList<>() Scanner input1 = new Scanner(System.in); input1 new Scanner(System.in) int length = input1.nextInt(); length input1.nextInt() input1.nextInt input1 int QUANTUM = input1.nextInt(); QUANTUM input1.nextInt() input1.nextInt input1 int totalTime=0; totalTime 0 int result; result String name; name input1.nextLine() input1.nextLine input1 for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        } int i=0; int i=0; i 0 i<length i length i++ i++ i {
            q.add(input1.nextLine());
        } {
            q.add(input1.nextLine());
        } q.add(input1.nextLine()) q.add q input1.nextLine() input1.nextLine input1 while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        } q.size()!=0 q.size() q.size q 0 {
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        } String removed = q.remove(); removed q.remove() q.remove q String[] removeItem = removed.split(" "); removeItem removed.split(" ") removed.split removed " " name =removeItem[0] name removeItem[0] removeItem 0 result = Integer.valueOf(removeItem[1])-QUANTUM result Integer.valueOf(removeItem[1])-QUANTUM Integer.valueOf(removeItem[1]) Integer.valueOf Integer removeItem[1] removeItem 1 QUANTUM if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            } result >0 result 0 {
                q.add(name+" "+result);
                totalTime += QUANTUM;
            } q.add(name+" "+result) q.add q name+" "+result name+" "+result name " " result totalTime += QUANTUM totalTime QUANTUM {
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            } totalTime += result+QUANTUM totalTime result+QUANTUM result QUANTUM System.out.println(name+" "+totalTime) System.out.println System.out System System.out name+" "+totalTime name+" "+totalTime name " " totalTime String[] args args public class Main{
    public static void main(String[] args) {
        Queue<String> q = new LinkedList<>();

        Scanner input1 = new Scanner(System.in);
        int length = input1.nextInt();
        int QUANTUM = input1.nextInt();
        int totalTime=0;
        int result; // This is the time of each item
        String name;

        input1.nextLine();
        // Takes all the inputs and put into the queue
        for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        }

        while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        }
    }
} public class Main{
    public static void main(String[] args) {
        Queue<String> q = new LinkedList<>();

        Scanner input1 = new Scanner(System.in);
        int length = input1.nextInt();
        int QUANTUM = input1.nextInt();
        int totalTime=0;
        int result; // This is the time of each item
        String name;

        input1.nextLine();
        // Takes all the inputs and put into the queue
        for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        }

        while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

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

// You cant store primitive types in queue?

public class Main{
    public static void main(String[] args) {
        Queue<String> q = new LinkedList<>();

        Scanner input1 = new Scanner(System.in);
        int length = input1.nextInt();
        int QUANTUM = input1.nextInt();
        int totalTime=0;
        int result; // This is the time of each item
        String name;

        input1.nextLine();
        // Takes all the inputs and put into the queue
        for(int i=0;i<length;i++){
            q.add(input1.nextLine());
        }

        while (q.size()!=0){
            String removed = q.remove();
            String[] removeItem = removed.split(" ");

            name =removeItem[0];
            result = Integer.valueOf(removeItem[1])-QUANTUM;
            if (result >0){
                q.add(name+" "+result);
                totalTime += QUANTUM;
            }
            else{
                totalTime += result+QUANTUM;
                System.out.println(name+" "+totalTime);
            }

        }
    }
}

