import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();
        Deque<Proc> st = new ArrayDeque<Proc>(n);
        while (n-- > 0) {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        }
        
        int t = 0;
        while (st.isEmpty() == false) {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        }
    }
    
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
    
    private static class Proc {
        String name;
        int time;
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
        public int getTime() {return time;}
        public int subTime(int t) {time -= t; return time;}
        public String getName() {return name;}
    }
} import java.util.*; util.* java public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();
        Deque<Proc> st = new ArrayDeque<Proc>(n);
        while (n-- > 0) {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        }
        
        int t = 0;
        while (st.isEmpty() == false) {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        }
    }
    
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
    
    private static class Proc {
        String name;
        int time;
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
        public int getTime() {return time;}
        public int subTime(int t) {time -= t; return time;}
        public String getName() {return name;}
    }
} Main public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    } main {
        Main main = new Main();
        main.solv();
    } Main main = new Main(); main new Main() main.solv() main.solv main String[] args args private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();
        Deque<Proc> st = new ArrayDeque<Proc>(n);
        while (n-- > 0) {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        }
        
        int t = 0;
        while (st.isEmpty() == false) {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        }
    } solv {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();
        Deque<Proc> st = new ArrayDeque<Proc>(n);
        while (n-- > 0) {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        }
        
        int t = 0;
        while (st.isEmpty() == false) {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        }
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input int q = input.nextInt(); q input.nextInt() input.nextInt input Deque<Proc> st = new ArrayDeque<Proc>(n); st new ArrayDeque<Proc>(n) while (n-- > 0) {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        } n-- > 0 n-- n 0 {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        } String name = input.next(); name input.next() input.next input int time = input.nextInt(); time input.nextInt() input.nextInt input st.add(new Proc(name, time)) st.add st new Proc(name, time) int t = 0; t 0 while (st.isEmpty() == false) {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        } st.isEmpty() == false st.isEmpty() st.isEmpty st false {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        } Proc p = st.poll(); p st.poll() st.poll st if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            } p.getTime() <= q p.getTime() p.getTime p q {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } t += p.getTime() t p.getTime() p.getTime p System.out.println(p.getName() + " " + t) System.out.println System.out System System.out p.getName() + " " + t p.getName() + " " + t p.getName() p.getName p " " t {
                t += q;
                p.subTime(q);
                st.add(p);
            } t += q t q p.subTime(q) p.subTime p q st.add(p) st.add st p private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    } print {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    } StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (Object x : xs) sb.append(x.toString()).append(' '); Object x xs sb.append(x.toString()).append(' '); sb.append(x.toString()).append(' ') sb.append(x.toString()).append sb.append(x.toString()) sb.append sb x.toString() x.toString x ' ' System.out.println(sb.toString().trim()) System.out.println System.out System System.out sb.toString().trim() sb.toString().trim sb.toString() sb.toString sb Object[] xs xs private static class Proc {
        String name;
        int time;
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
        public int getTime() {return time;}
        public int subTime(int t) {time -= t; return time;}
        public String getName() {return name;}
    } Proc String name; name int time; time public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        } Proc {
            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 int getTime() {return time;} getTime {return time;} return time; time public int subTime(int t) {time -= t; return time;} subTime {time -= t; return time;} time -= t time t return time; time int t t public String getName() {return name;} getName {return name;} return name; name public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();
        Deque<Proc> st = new ArrayDeque<Proc>(n);
        while (n-- > 0) {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        }
        
        int t = 0;
        while (st.isEmpty() == false) {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        }
    }
    
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
    
    private static class Proc {
        String name;
        int time;
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
        public int getTime() {return time;}
        public int subTime(int t) {time -= t; return time;}
        public String getName() {return name;}
    }
} public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();
        Deque<Proc> st = new ArrayDeque<Proc>(n);
        while (n-- > 0) {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        }
        
        int t = 0;
        while (st.isEmpty() == false) {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        }
    }
    
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
    
    private static class Proc {
        String name;
        int time;
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
        public int getTime() {return time;}
        public int subTime(int t) {time -= t; return time;}
        public String getName() {return name;}
    }
} Main
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();
        Deque<Proc> st = new ArrayDeque<Proc>(n);
        while (n-- > 0) {
            String name = input.next();
            int time = input.nextInt();
            st.add(new Proc(name, time));
        }
        
        int t = 0;
        while (st.isEmpty() == false) {
            Proc p = st.poll();
            if (p.getTime() <= q) {
                t += p.getTime();
                System.out.println(p.getName() + " " + t);
            } else {
                t += q;
                p.subTime(q);
                st.add(p);
            }
        }
    }
    
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
    
    private static class Proc {
        String name;
        int time;
        public Proc(String name, int time) {
            this.name = name;
            this.time = time;
        }
        public int getTime() {return time;}
        public int subTime(int t) {time -= t; return time;}
        public String getName() {return name;}
    }
}