import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int totalTime = 0;
        ArrayDeque<Process> queue = new ArrayDeque<Process>();
        for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        }
        while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        }

    }
    static class Process{
        private String name;
        private int time;
        public Process(String name, int time){
            this.name = name;
            this.time = time;
        }
        public int getTime(){
            return this.time;
        }
        public String getName(){
            return this.name;
        }
        public void reduceTime(int q){
            this.time -= q;
        }

    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}
 import java.io.*; io.* java import java.util.*; util.* java public class Main {

    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int totalTime = 0;
        ArrayDeque<Process> queue = new ArrayDeque<Process>();
        for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        }
        while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        }

    }
    static class Process{
        private String name;
        private int time;
        public Process(String name, int time){
            this.name = name;
            this.time = time;
        }
        public int getTime(){
            return this.time;
        }
        public String getName(){
            return this.name;
        }
        public void reduceTime(int q){
            this.time -= q;
        }

    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
} Main public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int totalTime = 0;
        ArrayDeque<Process> queue = new ArrayDeque<Process>();
        for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        }
        while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        }

    } main {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int totalTime = 0;
        ArrayDeque<Process> queue = new ArrayDeque<Process>();
        for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        }
        while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        }

    } FastScanner sc = new FastScanner(System.in); sc new FastScanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc int totalTime = 0; totalTime 0 ArrayDeque<Process> queue = new ArrayDeque<Process>(); queue new ArrayDeque<Process>() for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        } {
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        } String name = sc.next(); name sc.next() sc.next sc int time = sc.nextInt(); time sc.nextInt() sc.nextInt sc Process process = new Process(name, time); process new Process(name, time) queue.offerLast(process) queue.offerLast queue process while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        } queue.size() > 0 queue.size() queue.size queue 0 {
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        } Process process = queue.pollFirst(); process queue.pollFirst() queue.pollFirst queue int time = process.getTime(); time process.getTime() process.getTime process if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            } time <= q time q {
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            } totalTime += time totalTime time System.out.println(process.getName() + " " + totalTime) System.out.println System.out System System.out process.getName() + " " + totalTime process.getName() + " " + totalTime process.getName() process.getName process " " totalTime {
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            } totalTime += q totalTime q process.reduceTime(q) process.reduceTime process q queue.offerLast(process) queue.offerLast queue process String[] args args static class Process{
        private String name;
        private int time;
        public Process(String name, int time){
            this.name = name;
            this.time = time;
        }
        public int getTime(){
            return this.time;
        }
        public String getName(){
            return this.name;
        }
        public void reduceTime(int q){
            this.time -= q;
        }

    } Process private String name; name private int time; time public Process(String name, int time){
            this.name = name;
            this.time = time;
        } Process {
            this.name = name;
            this.time = time;
        } this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public int getTime(){
            return this.time;
        } getTime {
            return this.time;
        } return this.time; this.time this this.time public String getName(){
            return this.name;
        } getName {
            return this.name;
        } return this.name; this.name this this.name public void reduceTime(int q){
            this.time -= q;
        } reduceTime {
            this.time -= q;
        } this.time -= q this.time this this.time q int q q static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    } FastScanner private BufferedReader reader = null; reader null private StringTokenizer tokenizer = null; tokenizer null public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        } FastScanner {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        } reader = new BufferedReader(new InputStreamReader(in)) reader new BufferedReader(new InputStreamReader(in)) tokenizer = null tokenizer null InputStream in in public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } next {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } IOException e {
                    throw new RuntimeException(e);
                } throw new RuntimeException(e); new RuntimeException(e) {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        } nextLine {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        } if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } IOException e {
                    throw new RuntimeException(e);
                } throw new RuntimeException(e); new RuntimeException(e) {
                    return reader.readLine();
                } return reader.readLine(); reader.readLine() reader.readLine reader return tokenizer.nextToken("\n"); tokenizer.nextToken("\n") tokenizer.nextToken tokenizer "\n" public long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {

    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int totalTime = 0;
        ArrayDeque<Process> queue = new ArrayDeque<Process>();
        for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        }
        while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        }

    }
    static class Process{
        private String name;
        private int time;
        public Process(String name, int time){
            this.name = name;
            this.time = time;
        }
        public int getTime(){
            return this.time;
        }
        public String getName(){
            return this.name;
        }
        public void reduceTime(int q){
            this.time -= q;
        }

    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
} public class Main {

    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int totalTime = 0;
        ArrayDeque<Process> queue = new ArrayDeque<Process>();
        for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        }
        while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        }

    }
    static class Process{
        private String name;
        private int time;
        public Process(String name, int time){
            this.name = name;
            this.time = time;
        }
        public int getTime(){
            return this.time;
        }
        public String getName(){
            return this.name;
        }
        public void reduceTime(int q){
            this.time -= q;
        }

    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
} Main
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int totalTime = 0;
        ArrayDeque<Process> queue = new ArrayDeque<Process>();
        for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        }
        while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        }

    }
    static class Process{
        private String name;
        private int time;
        public Process(String name, int time){
            this.name = name;
            this.time = time;
        }
        public int getTime(){
            return this.time;
        }
        public String getName(){
            return this.name;
        }
        public void reduceTime(int q){
            this.time -= q;
        }

    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

