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

public class Main{

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String[] row = scan.nextLine().split(" ");

        int n = Integer.parseInt(row[0]);
        int q = Integer.parseInt(row[1]);

        Queue<Process> que = new LinkedList<Process>();
        for (int i=0; i<n; i++) {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        }

        int resultTime = 0;
        while (que.size() > 0) {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        }

    }

    private final static class Process {
        public String name = null;
        public int processTime = 0;

        public Process(String name, int processTime) {
            this.name = name;
            this.processTime = processTime;
        }
    }
}
 import java.util.LinkedList; LinkedList 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 scan = new Scanner(System.in);
        String[] row = scan.nextLine().split(" ");

        int n = Integer.parseInt(row[0]);
        int q = Integer.parseInt(row[1]);

        Queue<Process> que = new LinkedList<Process>();
        for (int i=0; i<n; i++) {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        }

        int resultTime = 0;
        while (que.size() > 0) {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        }

    }

    private final static class Process {
        public String name = null;
        public int processTime = 0;

        public Process(String name, int processTime) {
            this.name = name;
            this.processTime = processTime;
        }
    }
} Main public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String[] row = scan.nextLine().split(" ");

        int n = Integer.parseInt(row[0]);
        int q = Integer.parseInt(row[1]);

        Queue<Process> que = new LinkedList<Process>();
        for (int i=0; i<n; i++) {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        }

        int resultTime = 0;
        while (que.size() > 0) {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        }

    } main {
        Scanner scan = new Scanner(System.in);
        String[] row = scan.nextLine().split(" ");

        int n = Integer.parseInt(row[0]);
        int q = Integer.parseInt(row[1]);

        Queue<Process> que = new LinkedList<Process>();
        for (int i=0; i<n; i++) {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        }

        int resultTime = 0;
        while (que.size() > 0) {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        }

    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String[] row = scan.nextLine().split(" "); row scan.nextLine().split(" ") scan.nextLine().split scan.nextLine() scan.nextLine scan " " int n = Integer.parseInt(row[0]); n Integer.parseInt(row[0]) Integer.parseInt Integer row[0] row 0 int q = Integer.parseInt(row[1]); q Integer.parseInt(row[1]) Integer.parseInt Integer row[1] row 1 Queue<Process> que = new LinkedList<Process>(); que new LinkedList<Process>() for (int i=0; i<n; i++) {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        } {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        } String[] strArray = scan.nextLine().split(" "); strArray scan.nextLine().split(" ") scan.nextLine().split scan.nextLine() scan.nextLine scan " " Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1])); process new Process(strArray[0],
					  Integer.parseInt(strArray[1])) que.offer(process) que.offer que process int resultTime = 0; resultTime 0 while (que.size() > 0) {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        } que.size() > 0 que.size() que.size que 0 {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        } Process process = que.poll(); process que.poll() que.poll que resultTime += q resultTime q if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            } (process.processTime = process.processTime - q) > 0 (process.processTime = process.processTime - q) process.processTime process process.processTime process.processTime - q process.processTime process process.processTime q 0 {

                que.offer(process);
                continue;
            } que.offer(process) que.offer que process continue; resultTime += process.processTime resultTime process.processTime process process.processTime System.out.println(process.name + " " + resultTime) System.out.println System.out System System.out process.name + " " + resultTime process.name + " " + resultTime process.name process process.name " " resultTime String args[] args private final static class Process {
        public String name = null;
        public int processTime = 0;

        public Process(String name, int processTime) {
            this.name = name;
            this.processTime = processTime;
        }
    } Process public String name = null; name null public int processTime = 0; processTime 0 public Process(String name, int processTime) {
            this.name = name;
            this.processTime = processTime;
        } Process {
            this.name = name;
            this.processTime = processTime;
        } this.name = name this.name this this.name name this.processTime = processTime this.processTime this this.processTime processTime String name name int processTime processTime public class Main{

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String[] row = scan.nextLine().split(" ");

        int n = Integer.parseInt(row[0]);
        int q = Integer.parseInt(row[1]);

        Queue<Process> que = new LinkedList<Process>();
        for (int i=0; i<n; i++) {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        }

        int resultTime = 0;
        while (que.size() > 0) {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        }

    }

    private final static class Process {
        public String name = null;
        public int processTime = 0;

        public Process(String name, int processTime) {
            this.name = name;
            this.processTime = processTime;
        }
    }
} public class Main{

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String[] row = scan.nextLine().split(" ");

        int n = Integer.parseInt(row[0]);
        int q = Integer.parseInt(row[1]);

        Queue<Process> que = new LinkedList<Process>();
        for (int i=0; i<n; i++) {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        }

        int resultTime = 0;
        while (que.size() > 0) {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        }

    }

    private final static class Process {
        public String name = null;
        public int processTime = 0;

        public Process(String name, int processTime) {
            this.name = name;
            this.processTime = processTime;
        }
    }
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String[] row = scan.nextLine().split(" ");

        int n = Integer.parseInt(row[0]);
        int q = Integer.parseInt(row[1]);

        Queue<Process> que = new LinkedList<Process>();
        for (int i=0; i<n; i++) {
            String[] strArray = scan.nextLine().split(" ");

            Process process = new Process(strArray[0],
					  Integer.parseInt(strArray[1]));
            que.offer(process);
        }

        int resultTime = 0;
        while (que.size() > 0) {
            Process process = que.poll();
            resultTime += q;
            if ((process.processTime = process.processTime - q) > 0) {

                que.offer(process);
                continue;
            }
            resultTime += process.processTime;

            System.out.println(process.name + " " + resultTime);
        }

    }

    private final static class Process {
        public String name = null;
        public int processTime = 0;

        public Process(String name, int processTime) {
            this.name = name;
            this.processTime = processTime;
        }
    }
}

