import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Deque<String> name = new ArrayDeque<>();
        Deque<Integer> time = new ArrayDeque<>();
        int totalTime = 0;
        for(int i = 0; i < n; i++){
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        }
        int sumTime = 0;
        Deque<String> finishName = new ArrayDeque<>();
        Deque<Integer> finishTime = new ArrayDeque<>();
        while(sumTime != totalTime){
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        }
        for(int i = 0; i < n; i++){
            System.out.println(finishName.poll() + " " + finishTime.poll());
        }
    }
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.Scanner; Scanner 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();
        Deque<String> name = new ArrayDeque<>();
        Deque<Integer> time = new ArrayDeque<>();
        int totalTime = 0;
        for(int i = 0; i < n; i++){
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        }
        int sumTime = 0;
        Deque<String> finishName = new ArrayDeque<>();
        Deque<Integer> finishTime = new ArrayDeque<>();
        while(sumTime != totalTime){
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        }
        for(int i = 0; i < n; i++){
            System.out.println(finishName.poll() + " " + finishTime.poll());
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Deque<String> name = new ArrayDeque<>();
        Deque<Integer> time = new ArrayDeque<>();
        int totalTime = 0;
        for(int i = 0; i < n; i++){
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        }
        int sumTime = 0;
        Deque<String> finishName = new ArrayDeque<>();
        Deque<Integer> finishTime = new ArrayDeque<>();
        while(sumTime != totalTime){
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        }
        for(int i = 0; i < n; i++){
            System.out.println(finishName.poll() + " " + finishTime.poll());
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Deque<String> name = new ArrayDeque<>();
        Deque<Integer> time = new ArrayDeque<>();
        int totalTime = 0;
        for(int i = 0; i < n; i++){
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        }
        int sumTime = 0;
        Deque<String> finishName = new ArrayDeque<>();
        Deque<Integer> finishTime = new ArrayDeque<>();
        while(sumTime != totalTime){
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        }
        for(int i = 0; i < n; i++){
            System.out.println(finishName.poll() + " " + finishTime.poll());
        }
    } 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 Deque<String> name = new ArrayDeque<>(); name new ArrayDeque<>() Deque<Integer> time = new ArrayDeque<>(); time new ArrayDeque<>() int totalTime = 0; totalTime 0 for(int i = 0; i < n; i++){
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        } {
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        } name.add(sc.next()) name.add name sc.next() sc.next sc int tmp = sc.nextInt(); tmp sc.nextInt() sc.nextInt sc time.add(tmp) time.add time tmp totalTime += tmp totalTime tmp int sumTime = 0; sumTime 0 Deque<String> finishName = new ArrayDeque<>(); finishName new ArrayDeque<>() Deque<Integer> finishTime = new ArrayDeque<>(); finishTime new ArrayDeque<>() while(sumTime != totalTime){
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        } sumTime != totalTime sumTime totalTime {
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        } int t = time.poll(); t time.poll() time.poll time if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            } t <= q t q {
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            } sumTime += t sumTime t finishTime.add(sumTime) finishTime.add finishTime sumTime finishName.add(name.poll()) finishName.add finishName name.poll() name.poll name {
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            } sumTime += q sumTime q time.add(t - q) time.add time t - q t q name.add(name.poll()) name.add name name.poll() name.poll name for(int i = 0; i < n; i++){
            System.out.println(finishName.poll() + " " + finishTime.poll());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            System.out.println(finishName.poll() + " " + finishTime.poll());
        } {
            System.out.println(finishName.poll() + " " + finishTime.poll());
        } System.out.println(finishName.poll() + " " + finishTime.poll()) System.out.println System.out System System.out finishName.poll() + " " + finishTime.poll() finishName.poll() + " " + finishTime.poll() finishName.poll() finishName.poll finishName " " finishTime.poll() finishTime.poll finishTime 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();
        Deque<String> name = new ArrayDeque<>();
        Deque<Integer> time = new ArrayDeque<>();
        int totalTime = 0;
        for(int i = 0; i < n; i++){
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        }
        int sumTime = 0;
        Deque<String> finishName = new ArrayDeque<>();
        Deque<Integer> finishTime = new ArrayDeque<>();
        while(sumTime != totalTime){
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        }
        for(int i = 0; i < n; i++){
            System.out.println(finishName.poll() + " " + finishTime.poll());
        }
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Deque<String> name = new ArrayDeque<>();
        Deque<Integer> time = new ArrayDeque<>();
        int totalTime = 0;
        for(int i = 0; i < n; i++){
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        }
        int sumTime = 0;
        Deque<String> finishName = new ArrayDeque<>();
        Deque<Integer> finishTime = new ArrayDeque<>();
        while(sumTime != totalTime){
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        }
        for(int i = 0; i < n; i++){
            System.out.println(finishName.poll() + " " + finishTime.poll());
        }
    }
} Main
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Deque<String> name = new ArrayDeque<>();
        Deque<Integer> time = new ArrayDeque<>();
        int totalTime = 0;
        for(int i = 0; i < n; i++){
            name.add(sc.next());
            int tmp = sc.nextInt();
            time.add(tmp);
            totalTime += tmp;
        }
        int sumTime = 0;
        Deque<String> finishName = new ArrayDeque<>();
        Deque<Integer> finishTime = new ArrayDeque<>();
        while(sumTime != totalTime){
            int t = time.poll();
            if(t <= q){
                sumTime += t;
                finishTime.add(sumTime);
                finishName.add(name.poll());
            }else{
                sumTime += q;
                time.add(t - q);
                name.add(name.poll());
            }
        }
        for(int i = 0; i < n; i++){
            System.out.println(finishName.poll() + " " + finishTime.poll());
        }
    }
}
