import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n, q;
        n = input.nextInt();
        q = input.nextInt(); 
        Queue<Process> queue = new ArrayDeque<Process>();
        for (int i = 0; i < n; ++i) {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        }
        ArrayList<Process> res = new ArrayList<Process>();
        int time = 0;
        while (!queue.isEmpty()) {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        }
        for (Process element : res) {
            System.out.println(element.getName() + " " + element.getTime());
        }
    }                
}

class Process {
    String name;
    int time;
    public Process() {
        name = "";
        time = 0;
    }
    public Process(String name, int time) {
        this.name = name;
        this.time = time;
    }        

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n, q;
        n = input.nextInt();
        q = input.nextInt(); 
        Queue<Process> queue = new ArrayDeque<Process>();
        for (int i = 0; i < n; ++i) {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        }
        ArrayList<Process> res = new ArrayList<Process>();
        int time = 0;
        while (!queue.isEmpty()) {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        }
        for (Process element : res) {
            System.out.println(element.getName() + " " + element.getTime());
        }
    }                
} Main static final int INF = 1000000000; INF 1000000000 public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n, q;
        n = input.nextInt();
        q = input.nextInt(); 
        Queue<Process> queue = new ArrayDeque<Process>();
        for (int i = 0; i < n; ++i) {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        }
        ArrayList<Process> res = new ArrayList<Process>();
        int time = 0;
        while (!queue.isEmpty()) {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        }
        for (Process element : res) {
            System.out.println(element.getName() + " " + element.getTime());
        }
    } main {                
        Scanner input = new Scanner(System.in);
        int n, q;
        n = input.nextInt();
        q = input.nextInt(); 
        Queue<Process> queue = new ArrayDeque<Process>();
        for (int i = 0; i < n; ++i) {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        }
        ArrayList<Process> res = new ArrayList<Process>();
        int time = 0;
        while (!queue.isEmpty()) {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        }
        for (Process element : res) {
            System.out.println(element.getName() + " " + element.getTime());
        }
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n n q; q n = input.nextInt() n input.nextInt() input.nextInt input q = input.nextInt() q input.nextInt() input.nextInt input Queue<Process> queue = new ArrayDeque<Process>(); queue new ArrayDeque<Process>() for (int i = 0; i < n; ++i) {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        } {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        } String name = input.next(); name input.next() input.next input int time = input.nextInt(); time input.nextInt() input.nextInt input Process element = new Process(name, time); element new Process(name, time) queue.add(element) queue.add queue element ArrayList<Process> res = new ArrayList<Process>(); res new ArrayList<Process>() int time = 0; time 0 while (!queue.isEmpty()) {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        } Process element = queue.poll(); element queue.poll() queue.poll queue if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            } element.getTime() <= q element.getTime() element.getTime element q {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } time += element.getTime() time element.getTime() element.getTime element res.add(new Process(element.getName(), time)) res.add res new Process(element.getName(), time) {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            } time += q time q element.setTime(element.getTime() - q) element.setTime element element.getTime() - q element.getTime() element.getTime element q queue.add(element) queue.add queue element for (Process element : res) {
            System.out.println(element.getName() + " " + element.getTime());
        } Process element res {
            System.out.println(element.getName() + " " + element.getTime());
        } {
            System.out.println(element.getName() + " " + element.getTime());
        } System.out.println(element.getName() + " " + element.getTime()) System.out.println System.out System System.out element.getName() + " " + element.getTime() element.getName() + " " + element.getTime() element.getName() element.getName element " " element.getTime() element.getTime element String[] args args class Process {
    String name;
    int time;
    public Process() {
        name = "";
        time = 0;
    }
    public Process(String name, int time) {
        this.name = name;
        this.time = time;
    }        

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }
} Process String name; name int time; time public Process() {
        name = "";
        time = 0;
    } Process {
        name = "";
        time = 0;
    } name = "" name "" time = 0 time 0 public Process(String name, int time) {
        this.name = name;
        this.time = time;
    } Process {
        this.name = name;
        this.time = time;
    } this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public String getName() {
        return name;
    } getName {
        return name;
    } return name; name public void setName(String name) {
        this.name = name;
    } setName {
        this.name = name;
    } this.name = name this.name this this.name name String name name public int getTime() {
        return time;
    } getTime {
        return time;
    } return time; time public void setTime(int time) {
        this.time = time;
    } setTime {
        this.time = time;
    } this.time = time this.time this this.time time int time time public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n, q;
        n = input.nextInt();
        q = input.nextInt(); 
        Queue<Process> queue = new ArrayDeque<Process>();
        for (int i = 0; i < n; ++i) {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        }
        ArrayList<Process> res = new ArrayList<Process>();
        int time = 0;
        while (!queue.isEmpty()) {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        }
        for (Process element : res) {
            System.out.println(element.getName() + " " + element.getTime());
        }
    }                
} public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n, q;
        n = input.nextInt();
        q = input.nextInt(); 
        Queue<Process> queue = new ArrayDeque<Process>();
        for (int i = 0; i < n; ++i) {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        }
        ArrayList<Process> res = new ArrayList<Process>();
        int time = 0;
        while (!queue.isEmpty()) {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        }
        for (Process element : res) {
            System.out.println(element.getName() + " " + element.getTime());
        }
    }                
} Main
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n, q;
        n = input.nextInt();
        q = input.nextInt(); 
        Queue<Process> queue = new ArrayDeque<Process>();
        for (int i = 0; i < n; ++i) {
            String name = input.next();
            int time = input.nextInt();
            Process element = new Process(name, time);
            queue.add(element);
        }
        ArrayList<Process> res = new ArrayList<Process>();
        int time = 0;
        while (!queue.isEmpty()) {
            Process element = queue.poll();
            if (element.getTime() <= q) {
                time += element.getTime();
                res.add(new Process(element.getName(), time));
            } else {
                time += q;
                element.setTime(element.getTime() - q);
                queue.add(element);
            }
        }
        for (Process element : res) {
            System.out.println(element.getName() + " " + element.getTime());
        }
    }                
}

class Process {
    String name;
    int time;
    public Process() {
        name = "";
        time = 0;
    }
    public Process(String name, int time) {
        this.name = name;
        this.time = time;
    }        

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }
}