import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Iterator;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> keys = new LinkedList<>();
        Queue<Integer> values = new LinkedList<>();
        Integer timestamp = 0;

        int ceiling = in.nextInt();
        int quantum = in.nextInt();
        while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        }

        while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        }
    }
}




 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util import java.util.Iterator; Iterator java.util public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> keys = new LinkedList<>();
        Queue<Integer> values = new LinkedList<>();
        Integer timestamp = 0;

        int ceiling = in.nextInt();
        int quantum = in.nextInt();
        while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        }

        while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> keys = new LinkedList<>();
        Queue<Integer> values = new LinkedList<>();
        Integer timestamp = 0;

        int ceiling = in.nextInt();
        int quantum = in.nextInt();
        while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        }

        while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        }
    } main {
        Scanner in = new Scanner(System.in);
        Queue<String> keys = new LinkedList<>();
        Queue<Integer> values = new LinkedList<>();
        Integer timestamp = 0;

        int ceiling = in.nextInt();
        int quantum = in.nextInt();
        while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        }

        while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        }
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) Queue<String> keys = new LinkedList<>(); keys new LinkedList<>() Queue<Integer> values = new LinkedList<>(); values new LinkedList<>() Integer timestamp = 0; timestamp 0 int ceiling = in.nextInt(); ceiling in.nextInt() in.nextInt in int quantum = in.nextInt(); quantum in.nextInt() in.nextInt in while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        } ceiling > 0 ceiling 0 {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        } keys.add(in.next()) keys.add keys in.next() in.next in values.add(in.nextInt()) values.add values in.nextInt() in.nextInt in --ceiling ceiling while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        } !values.isEmpty() values.isEmpty() values.isEmpty values {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        } if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            } values.peek() <= quantum values.peek() values.peek values quantum {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } timestamp += values.poll() timestamp values.poll() values.poll values System.out.println(keys.poll() + " " + timestamp) System.out.println System.out System System.out keys.poll() + " " + timestamp keys.poll() + " " + timestamp keys.poll() keys.poll keys " " timestamp {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            } int temp = values.poll() - quantum; temp values.poll() - quantum values.poll() values.poll values quantum String tempo = keys.poll(); tempo keys.poll() keys.poll keys keys.add(tempo) keys.add keys tempo values.add(temp) values.add values temp timestamp += quantum timestamp quantum String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> keys = new LinkedList<>();
        Queue<Integer> values = new LinkedList<>();
        Integer timestamp = 0;

        int ceiling = in.nextInt();
        int quantum = in.nextInt();
        while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        }

        while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> keys = new LinkedList<>();
        Queue<Integer> values = new LinkedList<>();
        Integer timestamp = 0;

        int ceiling = in.nextInt();
        int quantum = in.nextInt();
        while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        }

        while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        }
    }
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Iterator;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> keys = new LinkedList<>();
        Queue<Integer> values = new LinkedList<>();
        Integer timestamp = 0;

        int ceiling = in.nextInt();
        int quantum = in.nextInt();
        while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        }

        while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        }
    }
}





