#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long

const int N = 2e5 + 20;

int t, w, n, a[N];

typedef tree <
pair <int, int>, null_type,
     less<pair <int, int>>, rb_tree_tag, tree_order_statistics_node_update >
     ordered_set;
ordered_set s;

int main()
{
    ios::sync_with_stdio(false);

    cin >> t;
    for(int tc = 1; tc <= t; tc++)
    {
        cin >> w >> n;
        for(int i = 0; i < w; i++) cin >> a[i], a[i]--;
        sort(a, a + w);
        for(int i = w; i < 2 * w; i++) a[i] = a[i - w] + n;

        int k = w;
        w *= 2;
        s.clear();
        for(int i = 0; i < k; i++) s.insert({a[i], i});

        ll old_m = (*s.find_by_order((k + 1) / 2 - 1)).first;
        ll d = 0;
        for(int i = 0; i < k; i++) d += abs(a[i] - old_m);

        ll ans = d;
        for(int i = k; i < w; i++)
        {
            s.erase(s.find_by_order(s.order_of_key({a[i - k], i - k})));
            s.insert({a[i], i});


            ll m = (*s.find_by_order((k + 1) / 2 - 1)).first;
            d = d + abs(m - a[i]) - abs(old_m - a[i - k]);
            if(k % 2 == 0) d -= (m - old_m);

            old_m = m;
            ans = min(ans, d);
        }

        cout << "Case #" << tc << ": " << ans << "\n";
    }
}