import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Que {
    int head, tail, length;
    Node[] Narray;

    public Que(int inputN) {
        head = -1;
        tail = -1;
        length = inputN;
        Narray = new Node[inputN];
    }

    public void enQue(Node node) {
        tail += 1;
        Narray[tail % length] = node;
    }

    public Node deQue() {
        head += 1;
        return Narray[head % length];
    }

    public boolean isEmpty() {
        if (head == tail)
            return true;
        else
            return false;
    }
}

class Node {
    String pName;
    public int time;

    public Node(String pName, int time) {
        this.pName = pName;
        this.time = time;
    }
}

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] inputData;
        String[] nodeData;

        try {
            int totalTime = 0;
            inputData = br.readLine().split(" ");
            int n = Integer.parseInt(inputData[0]);
            int limitTime = Integer.parseInt(inputData[1]);
            Que q = new Que(n);
            Node tmpNode = null;
            for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            }
            while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Que {
    int head, tail, length;
    Node[] Narray;

    public Que(int inputN) {
        head = -1;
        tail = -1;
        length = inputN;
        Narray = new Node[inputN];
    }

    public void enQue(Node node) {
        tail += 1;
        Narray[tail % length] = node;
    }

    public Node deQue() {
        head += 1;
        return Narray[head % length];
    }

    public boolean isEmpty() {
        if (head == tail)
            return true;
        else
            return false;
    }
} Que int head head tail tail length; length Node[] Narray; Narray public Que(int inputN) {
        head = -1;
        tail = -1;
        length = inputN;
        Narray = new Node[inputN];
    } Que {
        head = -1;
        tail = -1;
        length = inputN;
        Narray = new Node[inputN];
    } head = -1 head -1 1 tail = -1 tail -1 1 length = inputN length inputN Narray = new Node[inputN] Narray new Node[inputN] inputN int inputN inputN public void enQue(Node node) {
        tail += 1;
        Narray[tail % length] = node;
    } enQue {
        tail += 1;
        Narray[tail % length] = node;
    } tail += 1 tail 1 Narray[tail % length] = node Narray[tail % length] Narray tail % length tail length node Node node node public Node deQue() {
        head += 1;
        return Narray[head % length];
    } deQue {
        head += 1;
        return Narray[head % length];
    } head += 1 head 1 return Narray[head % length]; Narray[head % length] Narray head % length head length public boolean isEmpty() {
        if (head == tail)
            return true;
        else
            return false;
    } isEmpty {
        if (head == tail)
            return true;
        else
            return false;
    } if (head == tail)
            return true;
        else
            return false; head == tail head tail return true; true return false; false class Node {
    String pName;
    public int time;

    public Node(String pName, int time) {
        this.pName = pName;
        this.time = time;
    }
} Node String pName; pName public int time; time public Node(String pName, int time) {
        this.pName = pName;
        this.time = time;
    } Node {
        this.pName = pName;
        this.time = time;
    } this.pName = pName this.pName this this.pName pName this.time = time this.time this this.time time String pName pName int time time class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] inputData;
        String[] nodeData;

        try {
            int totalTime = 0;
            inputData = br.readLine().split(" ");
            int n = Integer.parseInt(inputData[0]);
            int limitTime = Integer.parseInt(inputData[1]);
            Que q = new Que(n);
            Node tmpNode = null;
            for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            }
            while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} Main public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] inputData;
        String[] nodeData;

        try {
            int totalTime = 0;
            inputData = br.readLine().split(" ");
            int n = Integer.parseInt(inputData[0]);
            int limitTime = Integer.parseInt(inputData[1]);
            Que q = new Que(n);
            Node tmpNode = null;
            for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            }
            while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] inputData;
        String[] nodeData;

        try {
            int totalTime = 0;
            inputData = br.readLine().split(" ");
            int n = Integer.parseInt(inputData[0]);
            int limitTime = Integer.parseInt(inputData[1]);
            Que q = new Que(n);
            Node tmpNode = null;
            for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            }
            while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] inputData; inputData String[] nodeData; nodeData try {
            int totalTime = 0;
            inputData = br.readLine().split(" ");
            int n = Integer.parseInt(inputData[0]);
            int limitTime = Integer.parseInt(inputData[1]);
            Que q = new Que(n);
            Node tmpNode = null;
            for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            }
            while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } IOException e {
            e.printStackTrace();
        } e.printStackTrace() e.printStackTrace e {
            int totalTime = 0;
            inputData = br.readLine().split(" ");
            int n = Integer.parseInt(inputData[0]);
            int limitTime = Integer.parseInt(inputData[1]);
            Que q = new Que(n);
            Node tmpNode = null;
            for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            }
            while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            }
        } int totalTime = 0; totalTime 0 inputData = br.readLine().split(" ") inputData br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(inputData[0]); n Integer.parseInt(inputData[0]) Integer.parseInt Integer inputData[0] inputData 0 int limitTime = Integer.parseInt(inputData[1]); limitTime Integer.parseInt(inputData[1]) Integer.parseInt Integer inputData[1] inputData 1 Que q = new Que(n); q new Que(n) Node tmpNode = null; tmpNode null for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            } {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            } nodeData = br.readLine().split(" ") nodeData br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1]))) q.enQue q new Node(nodeData[0], Integer.parseInt(nodeData[1])) while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            } !q.isEmpty() q.isEmpty() q.isEmpty q {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            } tmpNode = q.deQue() tmpNode q.deQue() q.deQue q if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                } tmpNode.time <= limitTime tmpNode.time tmpNode tmpNode.time limitTime {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } totalTime += tmpNode.time totalTime tmpNode.time tmpNode tmpNode.time System.out.printf("%s %d\n", tmpNode.pName, totalTime) System.out.printf System.out System System.out "%s %d\n" tmpNode.pName tmpNode tmpNode.pName totalTime {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                } totalTime += limitTime totalTime limitTime tmpNode.time -= limitTime tmpNode.time tmpNode tmpNode.time limitTime q.enQue(tmpNode) q.enQue q tmpNode String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Que {
    int head, tail, length;
    Node[] Narray;

    public Que(int inputN) {
        head = -1;
        tail = -1;
        length = inputN;
        Narray = new Node[inputN];
    }

    public void enQue(Node node) {
        tail += 1;
        Narray[tail % length] = node;
    }

    public Node deQue() {
        head += 1;
        return Narray[head % length];
    }

    public boolean isEmpty() {
        if (head == tail)
            return true;
        else
            return false;
    }
}

class Node {
    String pName;
    public int time;

    public Node(String pName, int time) {
        this.pName = pName;
        this.time = time;
    }
}

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] inputData;
        String[] nodeData;

        try {
            int totalTime = 0;
            inputData = br.readLine().split(" ");
            int n = Integer.parseInt(inputData[0]);
            int limitTime = Integer.parseInt(inputData[1]);
            Que q = new Que(n);
            Node tmpNode = null;
            for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            }
            while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
