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

class Main {

    static class Process{
        String name;
        int time;

        Process(String n, int t){
            name = n;
            time = t;
        }
        void updateTime(int t){
            time -= t;
        }
    }


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

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++)
            queue.add(new Process(sc.next(), sc.nextInt()));

        int elapsed = 0;
        while (queue.size() > 0){
            Process p = queue.poll();
            if (p.time <= quantum){
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            }
            else{
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            }
        }
    }
}
 import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util import java.util.Queue; Queue java.util class Main {

    static class Process{
        String name;
        int time;

        Process(String n, int t){
            name = n;
            time = t;
        }
        void updateTime(int t){
            time -= t;
        }
    }


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

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++)
            queue.add(new Process(sc.next(), sc.nextInt()));

        int elapsed = 0;
        while (queue.size() > 0){
            Process p = queue.poll();
            if (p.time <= quantum){
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            }
            else{
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            }
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++)
            queue.add(new Process(sc.next(), sc.nextInt()));

        int elapsed = 0;
        while (queue.size() > 0){
            Process p = queue.poll();
            if (p.time <= quantum){
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            }
            else{
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++)
            queue.add(new Process(sc.next(), sc.nextInt()));

        int elapsed = 0;
        while (queue.size() > 0){
            Process p = queue.poll();
            if (p.time <= quantum){
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            }
            else{
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int quantum = sc.nextInt(); quantum sc.nextInt() sc.nextInt sc Queue<Process> queue = new LinkedList<>(); queue new LinkedList<>() for (int i = 0; i < n; i++)
            queue.add(new Process(sc.next(), sc.nextInt())); int i = 0; int i = 0; i 0 i < n i n i++ i++ i queue.add(new Process(sc.next(), sc.nextInt())); queue.add(new Process(sc.next(), sc.nextInt())) queue.add queue new Process(sc.next(), sc.nextInt()) int elapsed = 0; elapsed 0 while (queue.size() > 0){
            Process p = queue.poll();
            if (p.time <= quantum){
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            }
            else{
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            }
        } queue.size() > 0 queue.size() queue.size queue 0 {
            Process p = queue.poll();
            if (p.time <= quantum){
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            }
            else{
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            }
        } Process p = queue.poll(); p queue.poll() queue.poll queue if (p.time <= quantum){
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            }
            else{
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            } p.time <= quantum p.time p p.time quantum {
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            } elapsed += p.time elapsed p.time p p.time System.out.println(p.name + " " + elapsed) System.out.println System.out System System.out p.name + " " + elapsed p.name + " " + elapsed p.name p p.name " " elapsed {
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            } elapsed += quantum elapsed quantum p.updateTime(quantum) p.updateTime p quantum queue.offer(p) queue.offer queue p String[] args args static class Process{
        String name;
        int time;

        Process(String n, int t){
            name = n;
            time = t;
        }
        void updateTime(int t){
            time -= t;
        }
    } Process String name; name int time; time Process(String n, int t){
            name = n;
            time = t;
        } Process {
            name = n;
            time = t;
        } name = n name n time = t time t String n n int t t void updateTime(int t){
            time -= t;
        } updateTime {
            time -= t;
        } time -= t time t int t t
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Queue;

class Main {

    static class Process{
        String name;
        int time;

        Process(String n, int t){
            name = n;
            time = t;
        }
        void updateTime(int t){
            time -= t;
        }
    }


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

        int n = sc.nextInt();
        int quantum = sc.nextInt();

        Queue<Process> queue = new LinkedList<>();

        for (int i = 0; i < n; i++)
            queue.add(new Process(sc.next(), sc.nextInt()));

        int elapsed = 0;
        while (queue.size() > 0){
            Process p = queue.poll();
            if (p.time <= quantum){
                elapsed += p.time;
                System.out.println(p.name + " " + elapsed);
            }
            else{
                elapsed += quantum;
                p.updateTime(quantum);
                queue.offer(p);
            }
        }
    }
}

