import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

        public int run(int time) {
            int pre = this.time;
            this.time = Math.max(0, this.time - time);
            return pre - this.time;
        }

        public boolean isFinished() {
            return this.time == 0;
        }
    }

    class Result {
        final String name;
        final int finishedTime;
        public Result(String name, int time) {
            this.name = name;
            finishedTime = time;
        }
    }

    void solve() {
        // Input
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> que = new ArrayDeque<>();
        for(int i= 0; i<n;i++) {
            que.add(new Process(sc.next(), sc.nextInt()));
        }

        // Solve
        List<Result> results = new ArrayList<>();
        int time = 0;
        while (!que.isEmpty()) {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        }

        // Output
        for(Result result : results) {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        }
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}
 import java.util.*; util.* java public class Main {

    Scanner sc = new Scanner(System.in);

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

        public int run(int time) {
            int pre = this.time;
            this.time = Math.max(0, this.time - time);
            return pre - this.time;
        }

        public boolean isFinished() {
            return this.time == 0;
        }
    }

    class Result {
        final String name;
        final int finishedTime;
        public Result(String name, int time) {
            this.name = name;
            finishedTime = time;
        }
    }

    void solve() {
        // Input
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> que = new ArrayDeque<>();
        for(int i= 0; i<n;i++) {
            que.add(new Process(sc.next(), sc.nextInt()));
        }

        // Solve
        List<Result> results = new ArrayList<>();
        int time = 0;
        while (!que.isEmpty()) {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        }

        // Output
        for(Result result : results) {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        }
    }

    public static void main(String[] args) {
        new Main().solve();
    }
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) void solve() {
        // Input
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> que = new ArrayDeque<>();
        for(int i= 0; i<n;i++) {
            que.add(new Process(sc.next(), sc.nextInt()));
        }

        // Solve
        List<Result> results = new ArrayList<>();
        int time = 0;
        while (!que.isEmpty()) {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        }

        // Output
        for(Result result : results) {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        }
    } solve {
        // Input
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> que = new ArrayDeque<>();
        for(int i= 0; i<n;i++) {
            que.add(new Process(sc.next(), sc.nextInt()));
        }

        // Solve
        List<Result> results = new ArrayList<>();
        int time = 0;
        while (!que.isEmpty()) {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        }

        // Output
        for(Result result : results) {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        }
    } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Queue<Process> que = new ArrayDeque<>(); que new ArrayDeque<>() for(int i= 0; i<n;i++) {
            que.add(new Process(sc.next(), sc.nextInt()));
        } int i= 0; int i= 0; i 0 i<n i n i++ i++ i {
            que.add(new Process(sc.next(), sc.nextInt()));
        } {
            que.add(new Process(sc.next(), sc.nextInt()));
        } que.add(new Process(sc.next(), sc.nextInt())) que.add que new Process(sc.next(), sc.nextInt()) List<Result> results = new ArrayList<>(); results new ArrayList<>() int time = 0; time 0 while (!que.isEmpty()) {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        } !que.isEmpty() que.isEmpty() que.isEmpty que {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        } Process top = que.poll(); top que.poll() que.poll que time += top.run(q) time top.run(q) top.run top q if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            } top.isFinished() top.isFinished top {
                results.add(new Result(top.name, time));
            } results.add(new Result(top.name, time)) results.add results new Result(top.name, time) {
                que.add(top);
            } que.add(top) que.add que top for(Result result : results) {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        } Result result results {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        } {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        } System.out.println(String.format("%s %d", result.name, result.finishedTime)) System.out.println System.out System System.out String.format("%s %d", result.name, result.finishedTime) String.format String "%s %d" result.name result result.name result.finishedTime result result.finishedTime public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args class Process {
        final String name;
        int time;
        public Process(String name, int time) {
            this.name = name;
            this.time = time;
        }

        public int run(int time) {
            int pre = this.time;
            this.time = Math.max(0, this.time - time);
            return pre - this.time;
        }

        public boolean isFinished() {
            return this.time == 0;
        }
    } Process final String name; name int time; time 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 int run(int time) {
            int pre = this.time;
            this.time = Math.max(0, this.time - time);
            return pre - this.time;
        } run {
            int pre = this.time;
            this.time = Math.max(0, this.time - time);
            return pre - this.time;
        } int pre = this.time; pre this.time this this.time this.time = Math.max(0, this.time - time) this.time this this.time Math.max(0, this.time - time) Math.max Math 0 this.time - time this.time this this.time time return pre - this.time; pre - this.time pre this.time this this.time int time time public boolean isFinished() {
            return this.time == 0;
        } isFinished {
            return this.time == 0;
        } return this.time == 0; this.time == 0 this.time this this.time 0 class Result {
        final String name;
        final int finishedTime;
        public Result(String name, int time) {
            this.name = name;
            finishedTime = time;
        }
    } Result final String name; name final int finishedTime; finishedTime public Result(String name, int time) {
            this.name = name;
            finishedTime = time;
        } Result {
            this.name = name;
            finishedTime = time;
        } this.name = name this.name this this.name name finishedTime = time finishedTime time String name name int time time public class Main {

    Scanner sc = new Scanner(System.in);

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

        public int run(int time) {
            int pre = this.time;
            this.time = Math.max(0, this.time - time);
            return pre - this.time;
        }

        public boolean isFinished() {
            return this.time == 0;
        }
    }

    class Result {
        final String name;
        final int finishedTime;
        public Result(String name, int time) {
            this.name = name;
            finishedTime = time;
        }
    }

    void solve() {
        // Input
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> que = new ArrayDeque<>();
        for(int i= 0; i<n;i++) {
            que.add(new Process(sc.next(), sc.nextInt()));
        }

        // Solve
        List<Result> results = new ArrayList<>();
        int time = 0;
        while (!que.isEmpty()) {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        }

        // Output
        for(Result result : results) {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        }
    }

    public static void main(String[] args) {
        new Main().solve();
    }
} public class Main {

    Scanner sc = new Scanner(System.in);

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

        public int run(int time) {
            int pre = this.time;
            this.time = Math.max(0, this.time - time);
            return pre - this.time;
        }

        public boolean isFinished() {
            return this.time == 0;
        }
    }

    class Result {
        final String name;
        final int finishedTime;
        public Result(String name, int time) {
            this.name = name;
            finishedTime = time;
        }
    }

    void solve() {
        // Input
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> que = new ArrayDeque<>();
        for(int i= 0; i<n;i++) {
            que.add(new Process(sc.next(), sc.nextInt()));
        }

        // Solve
        List<Result> results = new ArrayList<>();
        int time = 0;
        while (!que.isEmpty()) {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        }

        // Output
        for(Result result : results) {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        }
    }

    public static void main(String[] args) {
        new Main().solve();
    }
} Main
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

        public int run(int time) {
            int pre = this.time;
            this.time = Math.max(0, this.time - time);
            return pre - this.time;
        }

        public boolean isFinished() {
            return this.time == 0;
        }
    }

    class Result {
        final String name;
        final int finishedTime;
        public Result(String name, int time) {
            this.name = name;
            finishedTime = time;
        }
    }

    void solve() {
        // Input
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Process> que = new ArrayDeque<>();
        for(int i= 0; i<n;i++) {
            que.add(new Process(sc.next(), sc.nextInt()));
        }

        // Solve
        List<Result> results = new ArrayList<>();
        int time = 0;
        while (!que.isEmpty()) {
            Process top = que.poll();
            time += top.run(q);
            if(top.isFinished()) {
                results.add(new Result(top.name, time));
            } else {
                que.add(top);
            }
        }

        // Output
        for(Result result : results) {
            System.out.println(String.format("%s %d", result.name, result.finishedTime));
        }
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}

