import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int time = 0;
        int [] T = new int[n];
        String [] Name = new String[n];
        Queue<Integer> L = new ArrayDeque<>();
        ArrayList<Integer> opt = new ArrayList<>();
        for(int i=0;i<n;i++){
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        }
        while(L.size()!=0){
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        }
        for(int i:opt) System.out.println(Name[i]+" "+T[i]);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int time = 0;
        int [] T = new int[n];
        String [] Name = new String[n];
        Queue<Integer> L = new ArrayDeque<>();
        ArrayList<Integer> opt = new ArrayList<>();
        for(int i=0;i<n;i++){
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        }
        while(L.size()!=0){
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        }
        for(int i:opt) System.out.println(Name[i]+" "+T[i]);
    }
} Main public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int time = 0;
        int [] T = new int[n];
        String [] Name = new String[n];
        Queue<Integer> L = new ArrayDeque<>();
        ArrayList<Integer> opt = new ArrayList<>();
        for(int i=0;i<n;i++){
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        }
        while(L.size()!=0){
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        }
        for(int i:opt) System.out.println(Name[i]+" "+T[i]);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int time = 0;
        int [] T = new int[n];
        String [] Name = new String[n];
        Queue<Integer> L = new ArrayDeque<>();
        ArrayList<Integer> opt = new ArrayList<>();
        for(int i=0;i<n;i++){
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        }
        while(L.size()!=0){
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        }
        for(int i:opt) System.out.println(Name[i]+" "+T[i]);
    } 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 int time = 0; time 0 int [] T = new int[n]; T new int[n] n String [] Name = new String[n]; Name new String[n] n Queue<Integer> L = new ArrayDeque<>(); L new ArrayDeque<>() ArrayList<Integer> opt = new ArrayList<>(); opt new ArrayList<>() for(int i=0;i<n;i++){
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        } {
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        } Name[i] = sc.next() Name[i] Name i sc.next() sc.next sc T[i] = sc.nextInt() T[i] T i sc.nextInt() sc.nextInt sc L.add(i) L.add L i while(L.size()!=0){
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        } L.size()!=0 L.size() L.size L 0 {
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        } int p_num = L.poll(); p_num L.poll() L.poll L if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            } T[p_num]-q>0 T[p_num]-q T[p_num] T p_num q 0 {
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            } time+=q time q T[p_num]-=q T[p_num] T p_num q L.add(p_num) L.add L p_num {
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            } time+=T[p_num] time T[p_num] T p_num T[p_num]=time T[p_num] T p_num time opt.add(p_num) opt.add opt p_num for(int i:opt) System.out.println(Name[i]+" "+T[i]); int i opt System.out.println(Name[i]+" "+T[i]); System.out.println(Name[i]+" "+T[i]) System.out.println System.out System System.out Name[i]+" "+T[i] Name[i]+" "+T[i] Name[i] Name i " " T[i] T i String [] args args public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int time = 0;
        int [] T = new int[n];
        String [] Name = new String[n];
        Queue<Integer> L = new ArrayDeque<>();
        ArrayList<Integer> opt = new ArrayList<>();
        for(int i=0;i<n;i++){
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        }
        while(L.size()!=0){
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        }
        for(int i:opt) System.out.println(Name[i]+" "+T[i]);
    }
} public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int time = 0;
        int [] T = new int[n];
        String [] Name = new String[n];
        Queue<Integer> L = new ArrayDeque<>();
        ArrayList<Integer> opt = new ArrayList<>();
        for(int i=0;i<n;i++){
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        }
        while(L.size()!=0){
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        }
        for(int i:opt) System.out.println(Name[i]+" "+T[i]);
    }
} Main
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int time = 0;
        int [] T = new int[n];
        String [] Name = new String[n];
        Queue<Integer> L = new ArrayDeque<>();
        ArrayList<Integer> opt = new ArrayList<>();
        for(int i=0;i<n;i++){
            Name[i] = sc.next();
            T[i] = sc.nextInt();
            L.add(i);
        }
        while(L.size()!=0){
            int p_num = L.poll();
            if(T[p_num]-q>0){
                time+=q;
                T[p_num]-=q;
                L.add(p_num);
            }
            else{
                time+=T[p_num];
                T[p_num]=time;
                opt.add(p_num);
            }
        }
        for(int i:opt) System.out.println(Name[i]+" "+T[i]);
    }
}
