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

public class Main {


    private Scanner sc;

    public static void main(String[] args) {
        new Main().solve();
    }

    private void solve() {
        sc = new Scanner(System.in);
        java.util.Queue<q1_3> queue = new ArrayDeque<q1_3>();
        int n = sc.nextInt();
        int q = sc.nextInt();

        for (int i = 0; i < n; i++) {
            queue.offer(new q1_3(sc.next(), sc.nextInt()));
        }
        int sum = 0;
        while (!queue.isEmpty()) {
            q1_3 now = queue.poll();
            int d = Math.min(q, now.time);
            now.time -= d;
            sum += d;
            if (now.time > 0) {
                queue.offer(now);
            } else {

                System.out.println(now.name + " " + sum);
            }
        }
    }
}

class q1_3 {
    String name;
    int time;

    public q1_3(String name, int time) {
        super();
        this.name = name;
        this.time = time;
    }

}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz