import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        myQueue que=new myQueue();
        
        int n=in.nextInt(),limit=in.nextInt(),sum=0;
        for(int i=0;i<n;i++)que.push(new process(in.next(), in.nextInt()));

        while(!que.isEmpty()){
            process p=que.pop();
            if(p.time<=limit){
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            }
            else{
                sum+=limit;
                p.time-=limit;
                que.push(p);
            }
        }
    }
}

class process{
    String p;
    int time;

    process(String p,int time){
        this.p=p;
        this.time=time;
    }
}

class myQueue{
    process array[];
    int top,tail;

    myQueue(){
        array=new process[1000000];
        top=1; tail=1;
    }

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

    void push(process x){
        array[tail]=x;
        tail++;
    }

    process pop(){
        process res=array[top];
        top++;
        return res;
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        myQueue que=new myQueue();
        
        int n=in.nextInt(),limit=in.nextInt(),sum=0;
        for(int i=0;i<n;i++)que.push(new process(in.next(), in.nextInt()));

        while(!que.isEmpty()){
            process p=que.pop();
            if(p.time<=limit){
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            }
            else{
                sum+=limit;
                p.time-=limit;
                que.push(p);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        myQueue que=new myQueue();
        
        int n=in.nextInt(),limit=in.nextInt(),sum=0;
        for(int i=0;i<n;i++)que.push(new process(in.next(), in.nextInt()));

        while(!que.isEmpty()){
            process p=que.pop();
            if(p.time<=limit){
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            }
            else{
                sum+=limit;
                p.time-=limit;
                que.push(p);
            }
        }
    } main {
        Scanner in=new Scanner(System.in);
        myQueue que=new myQueue();
        
        int n=in.nextInt(),limit=in.nextInt(),sum=0;
        for(int i=0;i<n;i++)que.push(new process(in.next(), in.nextInt()));

        while(!que.isEmpty()){
            process p=que.pop();
            if(p.time<=limit){
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            }
            else{
                sum+=limit;
                p.time-=limit;
                que.push(p);
            }
        }
    } Scanner in=new Scanner(System.in); in new Scanner(System.in) myQueue que=new myQueue(); que new myQueue() int n=in.nextInt() n in.nextInt() in.nextInt in limit=in.nextInt() limit in.nextInt() in.nextInt in sum=0; sum 0 for(int i=0;i<n;i++)que.push(new process(in.next(), in.nextInt())); int i=0; int i=0; i 0 i<n i n i++ i++ i que.push(new process(in.next(), in.nextInt())); que.push(new process(in.next(), in.nextInt())) que.push que new process(in.next(), in.nextInt()) while(!que.isEmpty()){
            process p=que.pop();
            if(p.time<=limit){
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            }
            else{
                sum+=limit;
                p.time-=limit;
                que.push(p);
            }
        } !que.isEmpty() que.isEmpty() que.isEmpty que {
            process p=que.pop();
            if(p.time<=limit){
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            }
            else{
                sum+=limit;
                p.time-=limit;
                que.push(p);
            }
        } process p=que.pop(); p que.pop() que.pop que if(p.time<=limit){
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            }
            else{
                sum+=limit;
                p.time-=limit;
                que.push(p);
            } p.time<=limit p.time p p.time limit {
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            } sum+=p.time sum p.time p p.time System.out.println(p.p+" "+sum) System.out.println System.out System System.out p.p+" "+sum p.p+" "+sum p.p p p.p " " sum {
                sum+=limit;
                p.time-=limit;
                que.push(p);
            } sum+=limit sum limit p.time-=limit p.time p p.time limit que.push(p) que.push que p String[] args args class process{
    String p;
    int time;

    process(String p,int time){
        this.p=p;
        this.time=time;
    }
} process String p; p int time; time process(String p,int time){
        this.p=p;
        this.time=time;
    } process {
        this.p=p;
        this.time=time;
    } this.p=p this.p this this.p p this.time=time this.time this this.time time String p p int time time class myQueue{
    process array[];
    int top,tail;

    myQueue(){
        array=new process[1000000];
        top=1; tail=1;
    }

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

    void push(process x){
        array[tail]=x;
        tail++;
    }

    process pop(){
        process res=array[top];
        top++;
        return res;
    }
} myQueue process array[]; array int top top tail; tail myQueue(){
        array=new process[1000000];
        top=1; tail=1;
    } myQueue {
        array=new process[1000000];
        top=1; tail=1;
    } array=new process[1000000] array new process[1000000] 1000000 top=1 top 1 tail=1 tail 1 boolean isEmpty(){
        if(top==tail)return true;
        else return false;
    } isEmpty {
        if(top==tail)return true;
        else return false;
    } if(top==tail)return true;
        else return false; top==tail top tail return true; true return false; false void push(process x){
        array[tail]=x;
        tail++;
    } push {
        array[tail]=x;
        tail++;
    } array[tail]=x array[tail] array tail x tail++ tail process x x process pop(){
        process res=array[top];
        top++;
        return res;
    } pop {
        process res=array[top];
        top++;
        return res;
    } process res=array[top]; res array[top] array top top++ top return res; res
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        myQueue que=new myQueue();
        
        int n=in.nextInt(),limit=in.nextInt(),sum=0;
        for(int i=0;i<n;i++)que.push(new process(in.next(), in.nextInt()));

        while(!que.isEmpty()){
            process p=que.pop();
            if(p.time<=limit){
                sum+=p.time;
                System.out.println(p.p+" "+sum);
            }
            else{
                sum+=limit;
                p.time-=limit;
                que.push(p);
            }
        }
    }
}

class process{
    String p;
    int time;

    process(String p,int time){
        this.p=p;
        this.time=time;
    }
}

class myQueue{
    process array[];
    int top,tail;

    myQueue(){
        array=new process[1000000];
        top=1; tail=1;
    }

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

    void push(process x){
        array[tail]=x;
        tail++;
    }

    process pop(){
        process res=array[top];
        top++;
        return res;
    }
}
