
import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created by sd on 2016/11/22.
 */
public class Main {
    static class Pair{
        String name;
        int left;
        Pair(String name, int left){
            this.name = name;
            this.left = left;
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        LinkedList<Pair> queue = new LinkedList<>();
        int n = sc.nextInt(), q = sc.nextInt();
        int time_w = 0;
        for(int i=0; i<n; i++){
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }
        while(!queue.isEmpty()){
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }

    }
} import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util public class Main {
    static class Pair{
        String name;
        int left;
        Pair(String name, int left){
            this.name = name;
            this.left = left;
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        LinkedList<Pair> queue = new LinkedList<>();
        int n = sc.nextInt(), q = sc.nextInt();
        int time_w = 0;
        for(int i=0; i<n; i++){
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }
        while(!queue.isEmpty()){
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }

    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        LinkedList<Pair> queue = new LinkedList<>();
        int n = sc.nextInt(), q = sc.nextInt();
        int time_w = 0;
        for(int i=0; i<n; i++){
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }
        while(!queue.isEmpty()){
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }

    } main {
        Scanner sc = new Scanner(System.in);
        LinkedList<Pair> queue = new LinkedList<>();
        int n = sc.nextInt(), q = sc.nextInt();
        int time_w = 0;
        for(int i=0; i<n; i++){
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }
        while(!queue.isEmpty()){
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) LinkedList<Pair> queue = new LinkedList<>(); queue new LinkedList<>() int n = sc.nextInt() n sc.nextInt() sc.nextInt sc q = sc.nextInt(); q sc.nextInt() sc.nextInt sc int time_w = 0; time_w 0 for(int i=0; i<n; i++){
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        } {
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        } String str = sc.next(); str sc.next() sc.next sc int time = sc.nextInt(); time sc.nextInt() sc.nextInt sc if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            } time > q time q {
                time_w += q;
                queue.add(new Pair(str, time-q));
            } time_w += q time_w q queue.add(new Pair(str, time-q)) queue.add queue new Pair(str, time-q) {
                time_w += time;
                System.out.println(str+" "+time_w);
            } time_w += time time_w time System.out.println(str+" "+time_w) System.out.println System.out System System.out str+" "+time_w str+" "+time_w str " " time_w while(!queue.isEmpty()){
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        } Pair p = queue.poll(); p queue.poll() queue.poll queue String str = p.name; str p.name p p.name int time = p.left; time p.left p p.left if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            } time > q time q {
                time_w += q;
                queue.add(new Pair(str, time-q));
            } time_w += q time_w q queue.add(new Pair(str, time-q)) queue.add queue new Pair(str, time-q) {
                time_w += time;
                System.out.println(str+" "+time_w);
            } time_w += time time_w time System.out.println(str+" "+time_w) System.out.println System.out System System.out str+" "+time_w str+" "+time_w str " " time_w String[] args args static class Pair{
        String name;
        int left;
        Pair(String name, int left){
            this.name = name;
            this.left = left;
        }
    } Pair String name; name int left; left Pair(String name, int left){
            this.name = name;
            this.left = left;
        } Pair {
            this.name = name;
            this.left = left;
        } this.name = name this.name this this.name name this.left = left this.left this this.left left String name name int left left public class Main {
    static class Pair{
        String name;
        int left;
        Pair(String name, int left){
            this.name = name;
            this.left = left;
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        LinkedList<Pair> queue = new LinkedList<>();
        int n = sc.nextInt(), q = sc.nextInt();
        int time_w = 0;
        for(int i=0; i<n; i++){
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }
        while(!queue.isEmpty()){
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }

    }
} public class Main {
    static class Pair{
        String name;
        int left;
        Pair(String name, int left){
            this.name = name;
            this.left = left;
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        LinkedList<Pair> queue = new LinkedList<>();
        int n = sc.nextInt(), q = sc.nextInt();
        int time_w = 0;
        for(int i=0; i<n; i++){
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }
        while(!queue.isEmpty()){
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }

    }
} Main

import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created by sd on 2016/11/22.
 */
public class Main {
    static class Pair{
        String name;
        int left;
        Pair(String name, int left){
            this.name = name;
            this.left = left;
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        LinkedList<Pair> queue = new LinkedList<>();
        int n = sc.nextInt(), q = sc.nextInt();
        int time_w = 0;
        for(int i=0; i<n; i++){
            String str = sc.next();
            int time = sc.nextInt();

            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }
        while(!queue.isEmpty()){
            Pair p = queue.poll();
            String str = p.name;
            int time = p.left;
            if(time > q){
                time_w += q;
                queue.add(new Pair(str, time-q));
            }else{
                time_w += time;
                System.out.println(str+" "+time_w);
            }
        }

    }
}