import java.io.*;
import java.util.concurrent.LinkedBlockingQueue;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        String[] names = new String[n];
        LinkedBlockingQueue<int[]> processes = new LinkedBlockingQueue<int[]>();
        int[] currentProcess;
        int time = 0;
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < n; i++) {
            input = br.readLine().split(" ");
            names[i] = input[0];
            processes.offer(new int[] {i, Integer.parseInt(input[1])});
        }

        while ((currentProcess = processes.poll()) != null) {
            if (currentProcess[1] <= q) {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } else {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            }
        }
        System.out.print(sb.toString());
    }
} import java.io.*; io.* java import java.util.concurrent.LinkedBlockingQueue; LinkedBlockingQueue java.util.concurrent class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        String[] names = new String[n];
        LinkedBlockingQueue<int[]> processes = new LinkedBlockingQueue<int[]>();
        int[] currentProcess;
        int time = 0;
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < n; i++) {
            input = br.readLine().split(" ");
            names[i] = input[0];
            processes.offer(new int[] {i, Integer.parseInt(input[1])});
        }

        while ((currentProcess = processes.poll()) != null) {
            if (currentProcess[1] <= q) {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } else {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            }
        }
        System.out.print(sb.toString());
    }
} Main public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        String[] names = new String[n];
        LinkedBlockingQueue<int[]> processes = new LinkedBlockingQueue<int[]>();
        int[] currentProcess;
        int time = 0;
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < n; i++) {
            input = br.readLine().split(" ");
            names[i] = input[0];
            processes.offer(new int[] {i, Integer.parseInt(input[1])});
        }

        while ((currentProcess = processes.poll()) != null) {
            if (currentProcess[1] <= q) {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } else {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            }
        }
        System.out.print(sb.toString());
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        String[] names = new String[n];
        LinkedBlockingQueue<int[]> processes = new LinkedBlockingQueue<int[]>();
        int[] currentProcess;
        int time = 0;
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < n; i++) {
            input = br.readLine().split(" ");
            names[i] = input[0];
            processes.offer(new int[] {i, Integer.parseInt(input[1])});
        }

        while ((currentProcess = processes.poll()) != null) {
            if (currentProcess[1] <= q) {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } else {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            }
        }
        System.out.print(sb.toString());
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(input[0]); n Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 int q = Integer.parseInt(input[1]); q Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 String[] names = new String[n]; names new String[n] n LinkedBlockingQueue<int[]> processes = new LinkedBlockingQueue<int[]>(); processes new LinkedBlockingQueue<int[]>() int[] currentProcess; currentProcess int time = 0; time 0 StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < n; i++) {
            input = br.readLine().split(" ");
            names[i] = input[0];
            processes.offer(new int[] {i, Integer.parseInt(input[1])});
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            input = br.readLine().split(" ");
            names[i] = input[0];
            processes.offer(new int[] {i, Integer.parseInt(input[1])});
        } {
            input = br.readLine().split(" ");
            names[i] = input[0];
            processes.offer(new int[] {i, Integer.parseInt(input[1])});
        } input = br.readLine().split(" ") input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " names[i] = input[0] names[i] names i input[0] input 0 processes.offer(new int[] {i, Integer.parseInt(input[1])}) processes.offer processes new int[] {i, Integer.parseInt(input[1])} while ((currentProcess = processes.poll()) != null) {
            if (currentProcess[1] <= q) {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } else {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            }
        } (currentProcess = processes.poll()) != null (currentProcess = processes.poll()) currentProcess processes.poll() processes.poll processes null {
            if (currentProcess[1] <= q) {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } else {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            }
        } if (currentProcess[1] <= q) {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } else {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            } currentProcess[1] <= q currentProcess[1] currentProcess 1 q {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } time += currentProcess[1] time currentProcess[1] currentProcess 1 sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n") sb.append(names[currentProcess[0]]).append(" ").append(time).append sb.append(names[currentProcess[0]]).append(" ").append(time) sb.append(names[currentProcess[0]]).append(" ").append sb.append(names[currentProcess[0]]).append(" ") sb.append(names[currentProcess[0]]).append sb.append(names[currentProcess[0]]) sb.append sb names[currentProcess[0]] names currentProcess[0] currentProcess 0 " " time "\n" {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            } time += q time q currentProcess[1] -= q currentProcess[1] currentProcess 1 q processes.offer(currentProcess) processes.offer processes currentProcess System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args
import java.io.*;
import java.util.concurrent.LinkedBlockingQueue;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int q = Integer.parseInt(input[1]);
        String[] names = new String[n];
        LinkedBlockingQueue<int[]> processes = new LinkedBlockingQueue<int[]>();
        int[] currentProcess;
        int time = 0;
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < n; i++) {
            input = br.readLine().split(" ");
            names[i] = input[0];
            processes.offer(new int[] {i, Integer.parseInt(input[1])});
        }

        while ((currentProcess = processes.poll()) != null) {
            if (currentProcess[1] <= q) {
                time += currentProcess[1];
                sb.append(names[currentProcess[0]]).append(" ").append(time).append("\n");
            } else {
                time += q;
                currentProcess[1] -= q;
                processes.offer(currentProcess);
            }
        }
        System.out.print(sb.toString());
    }
}