import java.util.*;

class CPU{
    int time;
    String name;
}

public class Main {
    public static void main(String[] Args){
        Scanner sc = new Scanner(System.in);
        Queue<CPU> que = new LinkedList<>();
        int n = sc.nextInt();
        CPU[] cc = new CPU[n];
        int q = sc.nextInt();
        sc.nextLine();
        for(int i=0;i<n;i++){
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        }
        int tot=0;
        while(!que.isEmpty()){
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        }
    }

}
 import java.util.*; util.* java class CPU{
    int time;
    String name;
} CPU int time; time String name; name public class Main {
    public static void main(String[] Args){
        Scanner sc = new Scanner(System.in);
        Queue<CPU> que = new LinkedList<>();
        int n = sc.nextInt();
        CPU[] cc = new CPU[n];
        int q = sc.nextInt();
        sc.nextLine();
        for(int i=0;i<n;i++){
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        }
        int tot=0;
        while(!que.isEmpty()){
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        }
    }

} Main public static void main(String[] Args){
        Scanner sc = new Scanner(System.in);
        Queue<CPU> que = new LinkedList<>();
        int n = sc.nextInt();
        CPU[] cc = new CPU[n];
        int q = sc.nextInt();
        sc.nextLine();
        for(int i=0;i<n;i++){
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        }
        int tot=0;
        while(!que.isEmpty()){
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        Queue<CPU> que = new LinkedList<>();
        int n = sc.nextInt();
        CPU[] cc = new CPU[n];
        int q = sc.nextInt();
        sc.nextLine();
        for(int i=0;i<n;i++){
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        }
        int tot=0;
        while(!que.isEmpty()){
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<CPU> que = new LinkedList<>(); que new LinkedList<>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc CPU[] cc = new CPU[n]; cc new CPU[n] n int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc for(int i=0;i<n;i++){
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        } {
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        } String[] tt = sc.nextLine().split(" "); tt sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " cc[i] = new CPU() cc[i] cc i new CPU() cc[i].name = tt[0] cc[i].name cc[i] cc i cc[i].name tt[0] tt 0 cc[i].time = Integer.parseInt(tt[1]) cc[i].time cc[i] cc i cc[i].time Integer.parseInt(tt[1]) Integer.parseInt Integer tt[1] tt 1 que.add(cc[i]) que.add que cc[i] cc i int tot=0; tot 0 while(!que.isEmpty()){
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        } !que.isEmpty() que.isEmpty() que.isEmpty que {
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        } CPU now = que.poll(); now que.poll() que.poll que if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            } now.time > q now.time now now.time q {
                now.time -= q;
                que.add(now);
                tot += q;
            } now.time -= q now.time now now.time q que.add(now) que.add que now tot += q tot q {
                tot += now.time;
                System.out.println(now.name + " " + tot);
            } tot += now.time tot now.time now now.time System.out.println(now.name + " " + tot) System.out.println System.out System System.out now.name + " " + tot now.name + " " + tot now.name now now.name " " tot String[] Args Args public class Main {
    public static void main(String[] Args){
        Scanner sc = new Scanner(System.in);
        Queue<CPU> que = new LinkedList<>();
        int n = sc.nextInt();
        CPU[] cc = new CPU[n];
        int q = sc.nextInt();
        sc.nextLine();
        for(int i=0;i<n;i++){
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        }
        int tot=0;
        while(!que.isEmpty()){
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        }
    }

} public class Main {
    public static void main(String[] Args){
        Scanner sc = new Scanner(System.in);
        Queue<CPU> que = new LinkedList<>();
        int n = sc.nextInt();
        CPU[] cc = new CPU[n];
        int q = sc.nextInt();
        sc.nextLine();
        for(int i=0;i<n;i++){
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        }
        int tot=0;
        while(!que.isEmpty()){
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        }
    }

} Main
import java.util.*;

class CPU{
    int time;
    String name;
}

public class Main {
    public static void main(String[] Args){
        Scanner sc = new Scanner(System.in);
        Queue<CPU> que = new LinkedList<>();
        int n = sc.nextInt();
        CPU[] cc = new CPU[n];
        int q = sc.nextInt();
        sc.nextLine();
        for(int i=0;i<n;i++){
            String[] tt = sc.nextLine().split(" ");
            cc[i] = new CPU();
            cc[i].name = tt[0];
            cc[i].time = Integer.parseInt(tt[1]);
            que.add(cc[i]);
        }
        int tot=0;
        while(!que.isEmpty()){
            CPU now = que.poll();//返回第一个元素，并删除
            if(now.time > q){
                now.time -= q;
                que.add(now);
                tot += q;
            }
            else{
                tot += now.time;
                System.out.println(now.name + " " + tot);
            }
        }
    }

}

