import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<Process> ad = new ArrayDeque<Process>();
        int[] n = createListInt(br.readLine());
        int totalTime = 0;
        for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        }
        int m = n[1];
        while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        }

    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
}

class Process {
    String name;
    int time;

    Process(String name, int time) {
        this.name = name;
        this.time = time;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.regex.Pattern; Pattern java.util.regex public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<Process> ad = new ArrayDeque<Process>();
        int[] n = createListInt(br.readLine());
        int totalTime = 0;
        for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        }
        int m = n[1];
        while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        }

    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<Process> ad = new ArrayDeque<Process>();
        int[] n = createListInt(br.readLine());
        int totalTime = 0;
        for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        }
        int m = n[1];
        while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        }

    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<Process> ad = new ArrayDeque<Process>();
        int[] n = createListInt(br.readLine());
        int totalTime = 0;
        for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        }
        int m = n[1];
        while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        }

    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Deque<Process> ad = new ArrayDeque<Process>(); ad new ArrayDeque<Process>() int[] n = createListInt(br.readLine()); n createListInt(br.readLine()) createListInt br.readLine() br.readLine br int totalTime = 0; totalTime 0 for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        } int i = 0; int i = 0; i 0 i < n[0] i n[0] n 0 i++ i++ i {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        } {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        } String[] lines = br.readLine().split(" "); lines br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " ad.add(new Process(lines[0], ip(lines[1]))) ad.add ad new Process(lines[0], ip(lines[1])) int m = n[1]; m n[1] n 1 while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        } !ad.isEmpty() ad.isEmpty() ad.isEmpty ad {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        } Process t = ad.poll(); t ad.poll() ad.poll ad if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            } m < t.time m t.time t t.time {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } ad.add(new Process(t.name, t.time - m)) ad.add ad new Process(t.name, t.time - m) totalTime+=m totalTime m {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            } totalTime+=t.time totalTime t.time t t.time System.out.println(t.name+" "+totalTime) System.out.println System.out System System.out t.name+" "+totalTime t.name+" "+totalTime t.name t t.name " " totalTime String[] args args static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    } isNumber {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    } return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find(); Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find() Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num) Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$") Pattern.compile Pattern "^\\-?[0-9]*\\.?[0-9]+$" num String num num static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    } createListInt {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    } String[] lines = line.split(" "); lines line.split(" ") line.split line " " int n = lines.length; n lines.length lines lines.length int[] list = new int[n]; list new int[n] n while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        } n-- > 0 n-- n 0 {
            list[n] = Integer.parseInt(lines[n]);
        } list[n] = Integer.parseInt(lines[n]) list[n] list n Integer.parseInt(lines[n]) Integer.parseInt Integer lines[n] lines n return list; list String line line static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    } createListLong {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    } String[] lines = line.split(" "); lines line.split(" ") line.split line " " int n = lines.length; n lines.length lines lines.length long[] list = new long[n]; list new long[n] n while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        } n-- > 0 n-- n 0 {
            list[n] = Long.parseLong(lines[n]);
        } list[n] = Long.parseLong(lines[n]) list[n] list n Long.parseLong(lines[n]) Long.parseLong Long lines[n] lines n return list; list String line line static int ip(String s) {
        return Integer.parseInt(s);
    } ip {
        return Integer.parseInt(s);
    } return Integer.parseInt(s); Integer.parseInt(s) Integer.parseInt Integer s String s s static long lp(String s) {
        return Long.parseLong(s);
    } lp {
        return Long.parseLong(s);
    } return Long.parseLong(s); Long.parseLong(s) Long.parseLong Long s String s s class Process {
    String name;
    int time;

    Process(String name, int time) {
        this.name = name;
        this.time = time;
    }
} Process String name; name int time; time 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 class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<Process> ad = new ArrayDeque<Process>();
        int[] n = createListInt(br.readLine());
        int totalTime = 0;
        for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        }
        int m = n[1];
        while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        }

    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<Process> ad = new ArrayDeque<Process>();
        int[] n = createListInt(br.readLine());
        int totalTime = 0;
        for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        }
        int m = n[1];
        while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        }

    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<Process> ad = new ArrayDeque<Process>();
        int[] n = createListInt(br.readLine());
        int totalTime = 0;
        for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        }
        int m = n[1];
        while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        }

    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
}

class Process {
    String name;
    int time;

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