import java.util.Scanner;

public class Main {

    static class P{
        String name;
        int time;
    }

    static int len = 100001;
    static P[] Q = new P[len];

    static int head = 0;
    static int tail = 0;

    static boolean isEmpty(){
        return head == tail;
    }

    static boolean isFull(){
        return head == (tail + 1) % len;
    }

    static void enqueue(P p){
        if(isFull()){
            throw new IndexOutOfBoundsException();
        }
        Q[tail] = p;

        tail = (tail + 1) % len;
    }

    static P dequeue(){
        if(isEmpty()){
            throw new IndexOutOfBoundsException();
        }
        P temp = Q[head];

        head = (head + 1) % len;
        return temp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        P p = null;
        int n = 0;
        int q = 0;
        int index = 0;
        String[] temp = null;
        while (sc.hasNextLine()){
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        }

        int sumTime = 0;//当前总运行时间

        P curr = null;
        while (head != tail){
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        }
    }


    static int min(int a,int b){
        return a > b ? b : a;
    }
}
 import java.util.Scanner; Scanner java.util public class Main {

    static class P{
        String name;
        int time;
    }

    static int len = 100001;
    static P[] Q = new P[len];

    static int head = 0;
    static int tail = 0;

    static boolean isEmpty(){
        return head == tail;
    }

    static boolean isFull(){
        return head == (tail + 1) % len;
    }

    static void enqueue(P p){
        if(isFull()){
            throw new IndexOutOfBoundsException();
        }
        Q[tail] = p;

        tail = (tail + 1) % len;
    }

    static P dequeue(){
        if(isEmpty()){
            throw new IndexOutOfBoundsException();
        }
        P temp = Q[head];

        head = (head + 1) % len;
        return temp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        P p = null;
        int n = 0;
        int q = 0;
        int index = 0;
        String[] temp = null;
        while (sc.hasNextLine()){
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        }

        int sumTime = 0;//当前总运行时间

        P curr = null;
        while (head != tail){
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        }
    }


    static int min(int a,int b){
        return a > b ? b : a;
    }
} Main static int len = 100001; len 100001 static P[] Q = new P[len]; Q new P[len] len static int head = 0; head 0 static int tail = 0; tail 0 static boolean isEmpty(){
        return head == tail;
    } isEmpty {
        return head == tail;
    } return head == tail; head == tail head tail static boolean isFull(){
        return head == (tail + 1) % len;
    } isFull {
        return head == (tail + 1) % len;
    } return head == (tail + 1) % len; head == (tail + 1) % len head (tail + 1) % len (tail + 1) tail 1 len static void enqueue(P p){
        if(isFull()){
            throw new IndexOutOfBoundsException();
        }
        Q[tail] = p;

        tail = (tail + 1) % len;
    } enqueue {
        if(isFull()){
            throw new IndexOutOfBoundsException();
        }
        Q[tail] = p;

        tail = (tail + 1) % len;
    } if(isFull()){
            throw new IndexOutOfBoundsException();
        } isFull() isFull {
            throw new IndexOutOfBoundsException();
        } throw new IndexOutOfBoundsException(); new IndexOutOfBoundsException() Q[tail] = p Q[tail] Q tail p tail = (tail + 1) % len tail (tail + 1) % len (tail + 1) tail 1 len P p p static P dequeue(){
        if(isEmpty()){
            throw new IndexOutOfBoundsException();
        }
        P temp = Q[head];

        head = (head + 1) % len;
        return temp;
    } dequeue {
        if(isEmpty()){
            throw new IndexOutOfBoundsException();
        }
        P temp = Q[head];

        head = (head + 1) % len;
        return temp;
    } if(isEmpty()){
            throw new IndexOutOfBoundsException();
        } isEmpty() isEmpty {
            throw new IndexOutOfBoundsException();
        } throw new IndexOutOfBoundsException(); new IndexOutOfBoundsException() P temp = Q[head]; temp Q[head] Q head head = (head + 1) % len head (head + 1) % len (head + 1) head 1 len return temp; temp public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        P p = null;
        int n = 0;
        int q = 0;
        int index = 0;
        String[] temp = null;
        while (sc.hasNextLine()){
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        }

        int sumTime = 0;//当前总运行时间

        P curr = null;
        while (head != tail){
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        P p = null;
        int n = 0;
        int q = 0;
        int index = 0;
        String[] temp = null;
        while (sc.hasNextLine()){
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        }

        int sumTime = 0;//当前总运行时间

        P curr = null;
        while (head != tail){
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) P p = null; p null int n = 0; n 0 int q = 0; q 0 int index = 0; index 0 String[] temp = null; temp null while (sc.hasNextLine()){
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        } sc.hasNextLine() sc.hasNextLine sc {
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        } if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            } n == 0 n 0 {
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            } temp = sc.nextLine().split(" ") temp sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " n = Integer.valueOf(temp[0]) n Integer.valueOf(temp[0]) Integer.valueOf Integer temp[0] temp 0 q = Integer.valueOf(temp[1]) q Integer.valueOf(temp[1]) Integer.valueOf Integer temp[1] temp 1 {
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            } temp = sc.nextLine().split(" ") temp sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " p = new P() p new P() p.name = temp[0] p.name p p.name temp[0] temp 0 p.time = Integer.valueOf(temp[1]) p.time p p.time Integer.valueOf(temp[1]) Integer.valueOf Integer temp[1] temp 1 enqueue(p) enqueue p index ++ index if(index == n){
                    break;
                } index == n index n {
                    break;
                } break; int sumTime = 0; sumTime 0 P curr = null; curr null while (head != tail){
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        } head != tail head tail {
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        } curr = dequeue() curr dequeue() dequeue int c = min(q,curr.time); c min(q,curr.time) min q curr.time curr curr.time curr.time -= c curr.time curr curr.time c sumTime += c sumTime c if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            } curr.time > 0 curr.time curr curr.time 0 {
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            } enqueue(curr) enqueue curr {
                System.out.println(curr.name + " " + sumTime);
            } System.out.println(curr.name + " " + sumTime) System.out.println System.out System System.out curr.name + " " + sumTime curr.name + " " + sumTime curr.name curr curr.name " " sumTime String[] args args static int min(int a,int b){
        return a > b ? b : a;
    } min {
        return a > b ? b : a;
    } return a > b ? b : a; a > b ? b : a a > b a b b a int a a int b b static class P{
        String name;
        int time;
    } P String name; name int time; time public class Main {

    static class P{
        String name;
        int time;
    }

    static int len = 100001;
    static P[] Q = new P[len];

    static int head = 0;
    static int tail = 0;

    static boolean isEmpty(){
        return head == tail;
    }

    static boolean isFull(){
        return head == (tail + 1) % len;
    }

    static void enqueue(P p){
        if(isFull()){
            throw new IndexOutOfBoundsException();
        }
        Q[tail] = p;

        tail = (tail + 1) % len;
    }

    static P dequeue(){
        if(isEmpty()){
            throw new IndexOutOfBoundsException();
        }
        P temp = Q[head];

        head = (head + 1) % len;
        return temp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        P p = null;
        int n = 0;
        int q = 0;
        int index = 0;
        String[] temp = null;
        while (sc.hasNextLine()){
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        }

        int sumTime = 0;//当前总运行时间

        P curr = null;
        while (head != tail){
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        }
    }


    static int min(int a,int b){
        return a > b ? b : a;
    }
} public class Main {

    static class P{
        String name;
        int time;
    }

    static int len = 100001;
    static P[] Q = new P[len];

    static int head = 0;
    static int tail = 0;

    static boolean isEmpty(){
        return head == tail;
    }

    static boolean isFull(){
        return head == (tail + 1) % len;
    }

    static void enqueue(P p){
        if(isFull()){
            throw new IndexOutOfBoundsException();
        }
        Q[tail] = p;

        tail = (tail + 1) % len;
    }

    static P dequeue(){
        if(isEmpty()){
            throw new IndexOutOfBoundsException();
        }
        P temp = Q[head];

        head = (head + 1) % len;
        return temp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        P p = null;
        int n = 0;
        int q = 0;
        int index = 0;
        String[] temp = null;
        while (sc.hasNextLine()){
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        }

        int sumTime = 0;//当前总运行时间

        P curr = null;
        while (head != tail){
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        }
    }


    static int min(int a,int b){
        return a > b ? b : a;
    }
} Main
import java.util.Scanner;

public class Main {

    static class P{
        String name;
        int time;
    }

    static int len = 100001;
    static P[] Q = new P[len];

    static int head = 0;
    static int tail = 0;

    static boolean isEmpty(){
        return head == tail;
    }

    static boolean isFull(){
        return head == (tail + 1) % len;
    }

    static void enqueue(P p){
        if(isFull()){
            throw new IndexOutOfBoundsException();
        }
        Q[tail] = p;

        tail = (tail + 1) % len;
    }

    static P dequeue(){
        if(isEmpty()){
            throw new IndexOutOfBoundsException();
        }
        P temp = Q[head];

        head = (head + 1) % len;
        return temp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        P p = null;
        int n = 0;
        int q = 0;
        int index = 0;
        String[] temp = null;
        while (sc.hasNextLine()){
            if(n == 0){
                temp = sc.nextLine().split(" ");
                n = Integer.valueOf(temp[0]);
                q = Integer.valueOf(temp[1]);
            }else{
                temp = sc.nextLine().split(" ");
                p = new P();
                p.name = temp[0];
                p.time = Integer.valueOf(temp[1]);
                enqueue(p);
                index ++;
                if(index == n){
                    break;
                }
            }
        }

        int sumTime = 0;//当前总运行时间

        P curr = null;
        while (head != tail){
            curr = dequeue();
            int c = min(q,curr.time);
            curr.time -= c;
            sumTime += c;
            if(curr.time > 0){
                //如果当前任务有剩余时间 则加入队列
                enqueue(curr);
            }else{
                System.out.println(curr.name + " " + sumTime);
            }
        }
    }


    static int min(int a,int b){
        return a > b ? b : a;
    }
}

