import java.util.Scanner;
import java.util.Arrays;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] processInfo = scanner.nextLine().split(" ");
        
        int processCount = Integer.parseInt(processInfo[0]);
        int quantum = Integer.parseInt(processInfo[1]);
        
        Queue queue = new Queue(processCount);
        
        for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        }
        int totalTime = 0;
        
        while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        }
        
    }
    
    private static class Queue {
        
        private Process[] data;
        private int top = 0;
        private int last = 0;
        
        public Queue(int size) {
            data = new Process[size + 1];
        }
        
        public void push(Process p) {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        }
        
        public Process poll() {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        }
        
        public boolean isEmpty() {
            return top == last;
        }
        
    }
    
    private static class Process {
        private String name = null;
        private int time = 0;
        public Process(String name, String time) {
            this.name = name;
            this.time = Integer.parseInt(time);
        }
        
        public int doTask(int quantum) {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        }
        
        public String getName() {
            return name;
        }
        
        public boolean hasDone() {
            return time <= 0;
        }
    }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util import java.util.StringJoiner; StringJoiner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] processInfo = scanner.nextLine().split(" ");
        
        int processCount = Integer.parseInt(processInfo[0]);
        int quantum = Integer.parseInt(processInfo[1]);
        
        Queue queue = new Queue(processCount);
        
        for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        }
        int totalTime = 0;
        
        while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        }
        
    }
    
    private static class Queue {
        
        private Process[] data;
        private int top = 0;
        private int last = 0;
        
        public Queue(int size) {
            data = new Process[size + 1];
        }
        
        public void push(Process p) {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        }
        
        public Process poll() {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        }
        
        public boolean isEmpty() {
            return top == last;
        }
        
    }
    
    private static class Process {
        private String name = null;
        private int time = 0;
        public Process(String name, String time) {
            this.name = name;
            this.time = Integer.parseInt(time);
        }
        
        public int doTask(int quantum) {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        }
        
        public String getName() {
            return name;
        }
        
        public boolean hasDone() {
            return time <= 0;
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] processInfo = scanner.nextLine().split(" ");
        
        int processCount = Integer.parseInt(processInfo[0]);
        int quantum = Integer.parseInt(processInfo[1]);
        
        Queue queue = new Queue(processCount);
        
        for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        }
        int totalTime = 0;
        
        while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        }
        
    } main {
        Scanner scanner = new Scanner(System.in);
        String[] processInfo = scanner.nextLine().split(" ");
        
        int processCount = Integer.parseInt(processInfo[0]);
        int quantum = Integer.parseInt(processInfo[1]);
        
        Queue queue = new Queue(processCount);
        
        for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        }
        int totalTime = 0;
        
        while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        }
        
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] processInfo = scanner.nextLine().split(" "); processInfo scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int processCount = Integer.parseInt(processInfo[0]); processCount Integer.parseInt(processInfo[0]) Integer.parseInt Integer processInfo[0] processInfo 0 int quantum = Integer.parseInt(processInfo[1]); quantum Integer.parseInt(processInfo[1]) Integer.parseInt Integer processInfo[1] processInfo 1 Queue queue = new Queue(processCount); queue new Queue(processCount) for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        } int i = 0; int i = 0; i 0 i < processCount i processCount i++ i++ i {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        } {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        } String[] p = scanner.nextLine().split(" "); p scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " queue.push(new Process(p[0], p[1])) queue.push queue new Process(p[0], p[1]) int totalTime = 0; totalTime 0 while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        } Process p = queue.poll(); p queue.poll() queue.poll queue int spend = p.doTask(quantum); spend p.doTask(quantum) p.doTask p quantum totalTime += spend totalTime spend if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            } p.hasDone() p.hasDone p {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } System.out.printf("%s %d%n", p.getName(), totalTime) System.out.printf System.out System System.out "%s %d%n" p.getName() p.getName p totalTime {
                queue.push(p);
            } queue.push(p) queue.push queue p String[] args args private static class Queue {
        
        private Process[] data;
        private int top = 0;
        private int last = 0;
        
        public Queue(int size) {
            data = new Process[size + 1];
        }
        
        public void push(Process p) {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        }
        
        public Process poll() {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        }
        
        public boolean isEmpty() {
            return top == last;
        }
        
    } Queue private Process[] data; data private int top = 0; top 0 private int last = 0; last 0 public Queue(int size) {
            data = new Process[size + 1];
        } Queue {
            data = new Process[size + 1];
        } data = new Process[size + 1] data new Process[size + 1] size + 1 size 1 int size size public void push(Process p) {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        } push {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        } data[last] = p data[last] data last p last++ last if (last >= data.length) {
                last = 0;
            } last >= data.length last data.length data data.length {
                last = 0;
            } last = 0 last 0 Process p p public Process poll() {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        } poll {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        } Process p = data[top]; p data[top] data top data[top] = null data[top] data top null top++ top if (top >= data.length) {
                top = 0;
            } top >= data.length top data.length data data.length {
                top = 0;
            } top = 0 top 0 return p; p public boolean isEmpty() {
            return top == last;
        } isEmpty {
            return top == last;
        } return top == last; top == last top last private static class Process {
        private String name = null;
        private int time = 0;
        public Process(String name, String time) {
            this.name = name;
            this.time = Integer.parseInt(time);
        }
        
        public int doTask(int quantum) {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        }
        
        public String getName() {
            return name;
        }
        
        public boolean hasDone() {
            return time <= 0;
        }
    } Process private String name = null; name null private int time = 0; time 0 public Process(String name, String time) {
            this.name = name;
            this.time = Integer.parseInt(time);
        } Process {
            this.name = name;
            this.time = Integer.parseInt(time);
        } this.name = name this.name this this.name name this.time = Integer.parseInt(time) this.time this this.time Integer.parseInt(time) Integer.parseInt Integer time String name name String time time public int doTask(int quantum) {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        } doTask {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        } int spend = quantum - Math.max(quantum - time, 0); spend quantum - Math.max(quantum - time, 0) quantum Math.max(quantum - time, 0) Math.max Math quantum - time quantum time 0 time = Math.max(time - quantum, 0) time Math.max(time - quantum, 0) Math.max Math time - quantum time quantum 0 return spend; spend int quantum quantum public String getName() {
            return name;
        } getName {
            return name;
        } return name; name public boolean hasDone() {
            return time <= 0;
        } hasDone {
            return time <= 0;
        } return time <= 0; time <= 0 time 0 public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] processInfo = scanner.nextLine().split(" ");
        
        int processCount = Integer.parseInt(processInfo[0]);
        int quantum = Integer.parseInt(processInfo[1]);
        
        Queue queue = new Queue(processCount);
        
        for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        }
        int totalTime = 0;
        
        while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        }
        
    }
    
    private static class Queue {
        
        private Process[] data;
        private int top = 0;
        private int last = 0;
        
        public Queue(int size) {
            data = new Process[size + 1];
        }
        
        public void push(Process p) {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        }
        
        public Process poll() {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        }
        
        public boolean isEmpty() {
            return top == last;
        }
        
    }
    
    private static class Process {
        private String name = null;
        private int time = 0;
        public Process(String name, String time) {
            this.name = name;
            this.time = Integer.parseInt(time);
        }
        
        public int doTask(int quantum) {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        }
        
        public String getName() {
            return name;
        }
        
        public boolean hasDone() {
            return time <= 0;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] processInfo = scanner.nextLine().split(" ");
        
        int processCount = Integer.parseInt(processInfo[0]);
        int quantum = Integer.parseInt(processInfo[1]);
        
        Queue queue = new Queue(processCount);
        
        for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        }
        int totalTime = 0;
        
        while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        }
        
    }
    
    private static class Queue {
        
        private Process[] data;
        private int top = 0;
        private int last = 0;
        
        public Queue(int size) {
            data = new Process[size + 1];
        }
        
        public void push(Process p) {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        }
        
        public Process poll() {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        }
        
        public boolean isEmpty() {
            return top == last;
        }
        
    }
    
    private static class Process {
        private String name = null;
        private int time = 0;
        public Process(String name, String time) {
            this.name = name;
            this.time = Integer.parseInt(time);
        }
        
        public int doTask(int quantum) {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        }
        
        public String getName() {
            return name;
        }
        
        public boolean hasDone() {
            return time <= 0;
        }
    }
} Main
import java.util.Scanner;
import java.util.Arrays;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] processInfo = scanner.nextLine().split(" ");
        
        int processCount = Integer.parseInt(processInfo[0]);
        int quantum = Integer.parseInt(processInfo[1]);
        
        Queue queue = new Queue(processCount);
        
        for (int i = 0; i < processCount; i++) {
            String[] p = scanner.nextLine().split(" ");
            queue.push(new Process(p[0], p[1]));
        }
        int totalTime = 0;
        
        while (!queue.isEmpty()) {
            Process p = queue.poll();
            int spend = p.doTask(quantum);
            
            totalTime += spend;
            if (p.hasDone()) {
                System.out.printf("%s %d%n", p.getName(), totalTime);
            } else {
                queue.push(p);
            }

        }
        
    }
    
    private static class Queue {
        
        private Process[] data;
        private int top = 0;
        private int last = 0;
        
        public Queue(int size) {
            data = new Process[size + 1];
        }
        
        public void push(Process p) {
            data[last] = p;
            last++;
            
            if (last >= data.length) {
                last = 0;
            }
        }
        
        public Process poll() {
            Process p = data[top];
            data[top] = null;
            top++;
            if (top >= data.length) {
                top = 0;
            }
            
            return p;
        }
        
        public boolean isEmpty() {
            return top == last;
        }
        
    }
    
    private static class Process {
        private String name = null;
        private int time = 0;
        public Process(String name, String time) {
            this.name = name;
            this.time = Integer.parseInt(time);
        }
        
        public int doTask(int quantum) {
            int spend = quantum - Math.max(quantum - time, 0);
            time = Math.max(time - quantum, 0);
            return spend;
        }
        
        public String getName() {
            return name;
        }
        
        public boolean hasDone() {
            return time <= 0;
        }
    }
}
