import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
  
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Integer> task = new ArrayDeque<>();
        String[] name = new String[n];
        int[] time = new int[n];
        for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        }
 
        sc.close();
 
        int t = 0;
        while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        }
    }
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Integer> task = new ArrayDeque<>();
        String[] name = new String[n];
        int[] time = new int[n];
        for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        }
 
        sc.close();
 
        int t = 0;
        while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Integer> task = new ArrayDeque<>();
        String[] name = new String[n];
        int[] time = new int[n];
        for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        }
 
        sc.close();
 
        int t = 0;
        while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
  
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Integer> task = new ArrayDeque<>();
        String[] name = new String[n];
        int[] time = new int[n];
        for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        }
 
        sc.close();
 
        int t = 0;
        while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc Queue<Integer> task = new ArrayDeque<>(); task new ArrayDeque<>() String[] name = new String[n]; name new String[n] n int[] time = new int[n]; time new int[n] n for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        } {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        } name[i] = sc.next() name[i] name i sc.next() sc.next sc time[i] = sc.nextInt() time[i] time i sc.nextInt() sc.nextInt sc task.add(i) task.add task i sc.close() sc.close sc int t = 0; t 0 while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        } !task.isEmpty() task.isEmpty() task.isEmpty task {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        } int i = task.poll(); i task.poll() task.poll task if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            } time[i] <= q time[i] time i q {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            } t += time[i] t time[i] time i System.out.printf("%s %d\n", name[i], t) System.out.printf System.out System System.out "%s %d\n" name[i] name i t {
                t += q;
                time[i] -= q;
                task.add(i);
            } t += q t q time[i] -= q time[i] time i q task.add(i) task.add task i String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Integer> task = new ArrayDeque<>();
        String[] name = new String[n];
        int[] time = new int[n];
        for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        }
 
        sc.close();
 
        int t = 0;
        while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Integer> task = new ArrayDeque<>();
        String[] name = new String[n];
        int[] time = new int[n];
        for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        }
 
        sc.close();
 
        int t = 0;
        while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        }
    }
} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
  
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Integer> task = new ArrayDeque<>();
        String[] name = new String[n];
        int[] time = new int[n];
        for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        }
 
        sc.close();
 
        int t = 0;
        while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        }
    }
}
