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

public class Main {
    public static void main(String args[]) {
        int n, q, time = 0;
        Queue<String> queueName = new ArrayDeque<String>();
        Queue<Integer> queueTime = new ArrayDeque<Integer>();
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        q = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < n; i++) {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        }

        while (!queueName.isEmpty()) {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main(String args[]) {
        int n, q, time = 0;
        Queue<String> queueName = new ArrayDeque<String>();
        Queue<Integer> queueTime = new ArrayDeque<Integer>();
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        q = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < n; i++) {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        }

        while (!queueName.isEmpty()) {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        }
    }
} Main public static void main(String args[]) {
        int n, q, time = 0;
        Queue<String> queueName = new ArrayDeque<String>();
        Queue<Integer> queueTime = new ArrayDeque<Integer>();
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        q = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < n; i++) {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        }

        while (!queueName.isEmpty()) {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        }
    } main {
        int n, q, time = 0;
        Queue<String> queueName = new ArrayDeque<String>();
        Queue<Integer> queueTime = new ArrayDeque<Integer>();
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        q = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < n; i++) {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        }

        while (!queueName.isEmpty()) {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        }
    } int n n q q time = 0; time 0 Queue<String> queueName = new ArrayDeque<String>(); queueName new ArrayDeque<String>() Queue<Integer> queueTime = new ArrayDeque<Integer>(); queueTime new ArrayDeque<Integer>() Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt() q sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc for (int i = 0; i < n; i++) {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        } {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        } String s[] = sc.nextLine().split(" "); s sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " queueName.add(s[0]) queueName.add queueName s[0] s 0 queueTime.add(Integer.parseInt(s[1])) queueTime.add queueTime Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 while (!queueName.isEmpty()) {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        } !queueName.isEmpty() queueName.isEmpty() queueName.isEmpty queueName {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        } String qn = queueName.poll(); qn queueName.poll() queueName.poll queueName int t = queueTime.poll(); t queueTime.poll() queueTime.poll queueTime time += (t > q)? q: t time (t > q)? q: t (t > q) t q q t if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            } t > q t q {
                queueTime.add(t - q);
                queueName.add(qn);
            } queueTime.add(t - q) queueTime.add queueTime t - q t q queueName.add(qn) queueName.add queueName qn {
                System.out.println(qn + " " + time);
            } System.out.println(qn + " " + time) System.out.println System.out System System.out qn + " " + time qn + " " + time qn " " time String args[] args public class Main {
    public static void main(String args[]) {
        int n, q, time = 0;
        Queue<String> queueName = new ArrayDeque<String>();
        Queue<Integer> queueTime = new ArrayDeque<Integer>();
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        q = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < n; i++) {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        }

        while (!queueName.isEmpty()) {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        }
    }
} public class Main {
    public static void main(String args[]) {
        int n, q, time = 0;
        Queue<String> queueName = new ArrayDeque<String>();
        Queue<Integer> queueTime = new ArrayDeque<Integer>();
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        q = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < n; i++) {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        }

        while (!queueName.isEmpty()) {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        }
    }
} Main
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) {
        int n, q, time = 0;
        Queue<String> queueName = new ArrayDeque<String>();
        Queue<Integer> queueTime = new ArrayDeque<Integer>();
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        q = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < n; i++) {
            String s[] = sc.nextLine().split(" ");
            queueName.add(s[0]);
            queueTime.add(Integer.parseInt(s[1]));
        }

        while (!queueName.isEmpty()) {
            String qn = queueName.poll();
            int t = queueTime.poll();

            time += (t > q)? q: t;

            if (t > q) {
                queueTime.add(t - q);
                queueName.add(qn);
            } else {
                System.out.println(qn + " " + time);
            }
        }
    }
}