
import java.util.*;

/**
 * B
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

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

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        }
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        }
    } main {

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<String> name_array = new ArrayDeque<String>(); name_array new ArrayDeque<String>() Queue<Integer> time_array = new ArrayDeque<Integer>(); time_array new ArrayDeque<Integer>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc int sum_time = 0; sum_time 0 for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        } {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        } name_array.add(sc.next()) name_array.add name_array sc.next() sc.next sc time_array.add(sc.nextInt()) time_array.add time_array sc.nextInt() sc.nextInt sc sc.close() sc.close sc while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        } name_array.peek() != null name_array.peek() name_array.peek name_array null {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        } String str = name_array.remove(); str name_array.remove() name_array.remove name_array int tmp = time_array.remove(); tmp time_array.remove() time_array.remove time_array if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            } tmp > q tmp q {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } name_array.add(str) name_array.add name_array str time_array.add(tmp - q) time_array.add time_array tmp - q tmp q sum_time += q sum_time q {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            } System.out.println(str + " " + (sum_time + tmp)) System.out.println System.out System System.out str + " " + (sum_time + tmp) str + " " + (sum_time + tmp) str " " (sum_time + tmp) sum_time tmp sum_time += tmp sum_time tmp String[] args args public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        }
    }
} public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        }
    }
} Main

import java.util.*;

/**
 * B
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        }
    }
}
