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<TimeTask> que = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        }
        
        int timePoint = 0;
        while (!que.isEmpty()) {
            TimeTask head = que.poll();

            if (head.time > quant) {
                timePoint += quant;
                head.addTime(-quant);
                que.add(head);
                
            } else {
                timePoint += head.time;
                System.out.println(head.task + " " + timePoint);
            }
        }
    }
    
    static class TimeTask {
        String task;
        int time;
        TimeTask (String task, int time) {
            this.task = task;
            this.time = time;
        }
        
        void addTime(int add) {
            time += add;
        }
    }
} 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<TimeTask> que = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        }
        
        int timePoint = 0;
        while (!que.isEmpty()) {
            TimeTask head = que.poll();

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

        Queue<TimeTask> que = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        }
        
        int timePoint = 0;
        while (!que.isEmpty()) {
            TimeTask head = que.poll();

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

        Queue<TimeTask> que = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        }
        
        int timePoint = 0;
        while (!que.isEmpty()) {
            TimeTask head = que.poll();

            if (head.time > quant) {
                timePoint += quant;
                head.addTime(-quant);
                que.add(head);
                
            } else {
                timePoint += head.time;
                System.out.println(head.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<TimeTask> que = new ArrayDeque<>(); que new ArrayDeque<>() for (int i = 0; i < n; i++) {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        } {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        } que.add(new TimeTask(sc.next(), sc.nextInt())) que.add que new TimeTask(sc.next(), sc.nextInt()) int timePoint = 0; timePoint 0 while (!que.isEmpty()) {
            TimeTask head = que.poll();

            if (head.time > quant) {
                timePoint += quant;
                head.addTime(-quant);
                que.add(head);
                
            } else {
                timePoint += head.time;
                System.out.println(head.task + " " + timePoint);
            }
        } !que.isEmpty() que.isEmpty() que.isEmpty que {
            TimeTask head = que.poll();

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

        Queue<TimeTask> que = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        }
        
        int timePoint = 0;
        while (!que.isEmpty()) {
            TimeTask head = que.poll();

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

        Queue<TimeTask> que = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        }
        
        int timePoint = 0;
        while (!que.isEmpty()) {
            TimeTask head = que.poll();

            if (head.time > quant) {
                timePoint += quant;
                head.addTime(-quant);
                que.add(head);
                
            } else {
                timePoint += head.time;
                System.out.println(head.task + " " + timePoint);
            }
        }
    }
    
    static class TimeTask {
        String task;
        int time;
        TimeTask (String task, int time) {
            this.task = task;
            this.time = time;
        }
        
        void addTime(int add) {
            time += add;
        }
    }
} 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<TimeTask> que = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            que.add(new TimeTask(sc.next(), sc.nextInt()));
        }
        
        int timePoint = 0;
        while (!que.isEmpty()) {
            TimeTask head = que.poll();

            if (head.time > quant) {
                timePoint += quant;
                head.addTime(-quant);
                que.add(head);
                
            } else {
                timePoint += head.time;
                System.out.println(head.task + " " + timePoint);
            }
        }
    }
    
    static class TimeTask {
        String task;
        int time;
        TimeTask (String task, int time) {
            this.task = task;
            this.time = time;
        }
        
        void addTime(int add) {
            time += add;
        }
    }
}
