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

public class Main{
        static class Pair {
                int quan=0;
                String val="";
                Pair(int x , String y){
                    this.quan = x;
                    this.val = y;
                }
            }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        }

        int elapse = 0;
        while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        }




    }

}
 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main{
        static class Pair {
                int quan=0;
                String val="";
                Pair(int x , String y){
                    this.quan = x;
                    this.val = y;
                }
            }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        }

        int elapse = 0;
        while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        }




    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        }

        int elapse = 0;
        while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        }




    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        }

        int elapse = 0;
        while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        }




    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int Q = sc.nextInt(); Q sc.nextInt() sc.nextInt sc Queue<Pair> q = new LinkedList<>(); q new LinkedList<>() for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        } {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        } String name = sc.next(); name sc.next() sc.next sc int quantum = sc.nextInt(); quantum sc.nextInt() sc.nextInt sc q.add(new Pair(quantum,name)) q.add q new Pair(quantum,name) int elapse = 0; elapse 0 while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        } !q.isEmpty() q.isEmpty() q.isEmpty q {
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        } Pair current = q.poll(); current q.poll() q.poll q int qu = current.quan; qu current.quan current current.quan if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            } qu > Q qu Q {
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            } current.quan = qu-Q current.quan current current.quan qu-Q qu Q elapse+=Q elapse Q q.add(current) q.add q current {
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            } elapse+=current.quan elapse current.quan current current.quan System.out.println(current.val +" "+elapse) System.out.println System.out System System.out current.val +" "+elapse current.val +" "+elapse current.val current current.val " " elapse String[] args args static class Pair {
                int quan=0;
                String val="";
                Pair(int x , String y){
                    this.quan = x;
                    this.val = y;
                }
            } Pair int quan=0; quan 0 String val=""; val "" Pair(int x , String y){
                    this.quan = x;
                    this.val = y;
                } Pair {
                    this.quan = x;
                    this.val = y;
                } this.quan = x this.quan this this.quan x this.val = y this.val this this.val y int x x String y y public class Main{
        static class Pair {
                int quan=0;
                String val="";
                Pair(int x , String y){
                    this.quan = x;
                    this.val = y;
                }
            }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        }

        int elapse = 0;
        while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        }




    }

} public class Main{
        static class Pair {
                int quan=0;
                String val="";
                Pair(int x , String y){
                    this.quan = x;
                    this.val = y;
                }
            }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        }

        int elapse = 0;
        while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        }




    }

} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
        static class Pair {
                int quan=0;
                String val="";
                Pair(int x , String y){
                    this.quan = x;
                    this.val = y;
                }
            }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            String name = sc.next();
            int quantum = sc.nextInt();
            q.add(new Pair(quantum,name));
        }

        int elapse = 0;
        while(!q.isEmpty()){
            Pair current = q.poll();
            int qu = current.quan;
            if(qu > Q){
                current.quan = qu-Q;
                elapse+=Q;
                q.add(current);
            }else{
                elapse+=current.quan;
                System.out.println(current.val +" "+elapse);
            }
        }




    }

}

