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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int quant = sc.nextInt();

        Queue<String> qTask = new ArrayDeque<>();
        Queue<Integer> qTime = new ArrayDeque<>();
        
        for (int i = 0; i < n; i++) {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        }
        
        int timePoint = 0;
        while (!qTask.isEmpty()) {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        }
    }
} import java.util.ArrayDeque; ArrayDeque 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 n = sc.nextInt();
        int quant = sc.nextInt();

        Queue<String> qTask = new ArrayDeque<>();
        Queue<Integer> qTime = new ArrayDeque<>();
        
        for (int i = 0; i < n; i++) {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        }
        
        int timePoint = 0;
        while (!qTask.isEmpty()) {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int quant = sc.nextInt();

        Queue<String> qTask = new ArrayDeque<>();
        Queue<Integer> qTime = new ArrayDeque<>();
        
        for (int i = 0; i < n; i++) {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        }
        
        int timePoint = 0;
        while (!qTask.isEmpty()) {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int quant = sc.nextInt();

        Queue<String> qTask = new ArrayDeque<>();
        Queue<Integer> qTime = new ArrayDeque<>();
        
        for (int i = 0; i < n; i++) {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        }
        
        int timePoint = 0;
        while (!qTask.isEmpty()) {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int quant = sc.nextInt(); quant sc.nextInt() sc.nextInt sc Queue<String> qTask = new ArrayDeque<>(); qTask new ArrayDeque<>() Queue<Integer> qTime = new ArrayDeque<>(); qTime new ArrayDeque<>() for (int i = 0; i < n; i++) {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        } {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        } qTask.add(sc.next()) qTask.add qTask sc.next() sc.next sc qTime.add(sc.nextInt()) qTime.add qTime sc.nextInt() sc.nextInt sc int timePoint = 0; timePoint 0 while (!qTask.isEmpty()) {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        } !qTask.isEmpty() qTask.isEmpty() qTask.isEmpty qTask {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        } String task = qTask.poll(); task qTask.poll() qTask.poll qTask int time = qTime.poll(); time qTime.poll() qTime.poll qTime if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            } time > quant time quant {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } timePoint += quant timePoint quant qTime.add(time - quant) qTime.add qTime time - quant time quant qTask.add(task) qTask.add qTask task {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            } timePoint += time timePoint time System.out.println(task + " " + timePoint) System.out.println System.out System System.out task + " " + timePoint task + " " + timePoint task " " timePoint String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int quant = sc.nextInt();

        Queue<String> qTask = new ArrayDeque<>();
        Queue<Integer> qTime = new ArrayDeque<>();
        
        for (int i = 0; i < n; i++) {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        }
        
        int timePoint = 0;
        while (!qTask.isEmpty()) {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int quant = sc.nextInt();

        Queue<String> qTask = new ArrayDeque<>();
        Queue<Integer> qTime = new ArrayDeque<>();
        
        for (int i = 0; i < n; i++) {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        }
        
        int timePoint = 0;
        while (!qTask.isEmpty()) {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        }
    }
} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int quant = sc.nextInt();

        Queue<String> qTask = new ArrayDeque<>();
        Queue<Integer> qTime = new ArrayDeque<>();
        
        for (int i = 0; i < n; i++) {
            qTask.add(sc.next());
            qTime.add(sc.nextInt());
        }
        
        int timePoint = 0;
        while (!qTask.isEmpty()) {
            String task = qTask.poll();
            int time = qTime.poll();

            if (time > quant) {
                timePoint += quant;
                qTime.add(time - quant);
                qTask.add(task);
               
            } else {
                timePoint += time;
                System.out.println(task + " " + timePoint);
            }
        }
    }
}
