import java.util.*;

class IntQue{
    final int MAX=100000;
    int[] q;
    int head,tail;
    IntQue(){
        q=new int[MAX];
        head=0;tail=0;
    }
    boolean isEmpty(){
        return head==tail;
    }
    void enqueue(int time){
        q[tail]=time;
        if(tail+1==MAX) tail=0;
        else tail++;
    }
    int dequeue(){
        int t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    }
}
class StringQue{
    final int MAX=100000;
    String[] q;
    int head,tail;
    StringQue(){
        q=new String[MAX];
        head=0;tail=0;
    }
    boolean isEmpty(){
        return head==tail;
    }
    void enqueue(String name){
        q[tail]=name;
        if(tail+1==MAX) tail=0;
        else tail++;
    }
    String dequeue(){
        String t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    }
}
public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        IntQue iq=new IntQue();
        StringQue sq=new StringQue();
        int n=sc.nextInt();
        int qms=sc.nextInt();
        for(int i=0;i<n;i++){
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        }
        int total=0;
        while(!(iq.isEmpty())){
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        }
    }
} import java.util.*; util.* java class IntQue{
    final int MAX=100000;
    int[] q;
    int head,tail;
    IntQue(){
        q=new int[MAX];
        head=0;tail=0;
    }
    boolean isEmpty(){
        return head==tail;
    }
    void enqueue(int time){
        q[tail]=time;
        if(tail+1==MAX) tail=0;
        else tail++;
    }
    int dequeue(){
        int t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    }
} IntQue final int MAX=100000; MAX 100000 int[] q; q int head head tail; tail IntQue(){
        q=new int[MAX];
        head=0;tail=0;
    } IntQue {
        q=new int[MAX];
        head=0;tail=0;
    } q=new int[MAX] q new int[MAX] MAX head=0 head 0 tail=0 tail 0 boolean isEmpty(){
        return head==tail;
    } isEmpty {
        return head==tail;
    } return head==tail; head==tail head tail void enqueue(int time){
        q[tail]=time;
        if(tail+1==MAX) tail=0;
        else tail++;
    } enqueue {
        q[tail]=time;
        if(tail+1==MAX) tail=0;
        else tail++;
    } q[tail]=time q[tail] q tail time if(tail+1==MAX) tail=0;
        else tail++; tail+1==MAX tail+1 tail 1 MAX tail=0 tail 0 tail++ tail int time time int dequeue(){
        int t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    } dequeue {
        int t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    } int t=q[head]; t q[head] q head if(head+1==MAX) head=0;
        else head++; head+1==MAX head+1 head 1 MAX head=0 head 0 head++ head return t; t class StringQue{
    final int MAX=100000;
    String[] q;
    int head,tail;
    StringQue(){
        q=new String[MAX];
        head=0;tail=0;
    }
    boolean isEmpty(){
        return head==tail;
    }
    void enqueue(String name){
        q[tail]=name;
        if(tail+1==MAX) tail=0;
        else tail++;
    }
    String dequeue(){
        String t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    }
} StringQue final int MAX=100000; MAX 100000 String[] q; q int head head tail; tail StringQue(){
        q=new String[MAX];
        head=0;tail=0;
    } StringQue {
        q=new String[MAX];
        head=0;tail=0;
    } q=new String[MAX] q new String[MAX] MAX head=0 head 0 tail=0 tail 0 boolean isEmpty(){
        return head==tail;
    } isEmpty {
        return head==tail;
    } return head==tail; head==tail head tail void enqueue(String name){
        q[tail]=name;
        if(tail+1==MAX) tail=0;
        else tail++;
    } enqueue {
        q[tail]=name;
        if(tail+1==MAX) tail=0;
        else tail++;
    } q[tail]=name q[tail] q tail name if(tail+1==MAX) tail=0;
        else tail++; tail+1==MAX tail+1 tail 1 MAX tail=0 tail 0 tail++ tail String name name String dequeue(){
        String t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    } dequeue {
        String t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    } String t=q[head]; t q[head] q head if(head+1==MAX) head=0;
        else head++; head+1==MAX head+1 head 1 MAX head=0 head 0 head++ head return t; t public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        IntQue iq=new IntQue();
        StringQue sq=new StringQue();
        int n=sc.nextInt();
        int qms=sc.nextInt();
        for(int i=0;i<n;i++){
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        }
        int total=0;
        while(!(iq.isEmpty())){
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        }
    }
} Main private static Scanner sc=new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args){
        IntQue iq=new IntQue();
        StringQue sq=new StringQue();
        int n=sc.nextInt();
        int qms=sc.nextInt();
        for(int i=0;i<n;i++){
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        }
        int total=0;
        while(!(iq.isEmpty())){
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        }
    } main {
        IntQue iq=new IntQue();
        StringQue sq=new StringQue();
        int n=sc.nextInt();
        int qms=sc.nextInt();
        for(int i=0;i<n;i++){
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        }
        int total=0;
        while(!(iq.isEmpty())){
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        }
    } IntQue iq=new IntQue(); iq new IntQue() StringQue sq=new StringQue(); sq new StringQue() int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int qms=sc.nextInt(); qms sc.nextInt() sc.nextInt sc for(int i=0;i<n;i++){
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        } {
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        } sq.enqueue(sc.next()) sq.enqueue sq sc.next() sc.next sc iq.enqueue(sc.nextInt()) iq.enqueue iq sc.nextInt() sc.nextInt sc int total=0; total 0 while(!(iq.isEmpty())){
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        } !(iq.isEmpty()) (iq.isEmpty()) iq.isEmpty iq {
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        } String name=sq.dequeue(); name sq.dequeue() sq.dequeue sq int time=iq.dequeue(); time iq.dequeue() iq.dequeue iq if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            } time>qms time qms {
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            } total=total+qms total total+qms total qms sq.enqueue(name) sq.enqueue sq name iq.enqueue(time-qms) iq.enqueue iq time-qms time qms {
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            } total=total+time total total+time total time System.out.printf("%s %d\n",name,total) System.out.printf System.out System System.out "%s %d\n" name total String[] args args public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        IntQue iq=new IntQue();
        StringQue sq=new StringQue();
        int n=sc.nextInt();
        int qms=sc.nextInt();
        for(int i=0;i<n;i++){
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        }
        int total=0;
        while(!(iq.isEmpty())){
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        }
    }
} public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        IntQue iq=new IntQue();
        StringQue sq=new StringQue();
        int n=sc.nextInt();
        int qms=sc.nextInt();
        for(int i=0;i<n;i++){
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        }
        int total=0;
        while(!(iq.isEmpty())){
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        }
    }
} Main
import java.util.*;

class IntQue{
    final int MAX=100000;
    int[] q;
    int head,tail;
    IntQue(){
        q=new int[MAX];
        head=0;tail=0;
    }
    boolean isEmpty(){
        return head==tail;
    }
    void enqueue(int time){
        q[tail]=time;
        if(tail+1==MAX) tail=0;
        else tail++;
    }
    int dequeue(){
        int t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    }
}
class StringQue{
    final int MAX=100000;
    String[] q;
    int head,tail;
    StringQue(){
        q=new String[MAX];
        head=0;tail=0;
    }
    boolean isEmpty(){
        return head==tail;
    }
    void enqueue(String name){
        q[tail]=name;
        if(tail+1==MAX) tail=0;
        else tail++;
    }
    String dequeue(){
        String t=q[head];
        if(head+1==MAX) head=0;
        else head++;
        return t;
    }
}
public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        IntQue iq=new IntQue();
        StringQue sq=new StringQue();
        int n=sc.nextInt();
        int qms=sc.nextInt();
        for(int i=0;i<n;i++){
            sq.enqueue(sc.next());
            iq.enqueue(sc.nextInt());
        }
        int total=0;
        while(!(iq.isEmpty())){
            String name=sq.dequeue();
            int time=iq.dequeue();
            if(time>qms){
                total=total+qms;
                sq.enqueue(name);
                iq.enqueue(time-qms);
            }else{
                total=total+time;
                System.out.printf("%s %d\n",name,total);
            }
        }
    }
}