#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define T int t = 0; cin >> t; while(t--)
#define pr(a) for(int i = 0; i < (int)a.size(); ++i)cout << a[i] << " ";cout << endl;
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 2;
const ll inf = 2e18;
const int sz = 256;
const int max_k = 20;
const int len = 2e5 + 2;
typedef long long ll;
void solve(){
int w, n;
cin >> w >> n;
vector<ll>a(2 * w);
f(i, w)cin >> a[i];
sort(a.begin(), a.begin() + w);
for(int i = w; i < 2 * w ; ++i)a[i] = a[i - w] + n;
vector<ll>pref(2 * w);
pref[0] = a[0];
for(int i = 1; i < 2 * w; ++i)pref[i] = pref[i - 1] + a[i];
auto get_sum = [&](int i , int j){
return pref[j] - (i > 0 ? pref[i - 1] : 0);
};
auto get = [&](int i){
int j = i + w - 1;
int k = a[(i + j) >> 1];
ll sum_left = get_sum(i, (i + j) >> 1);
ll sum_right = get_sum((i + j) >> 1 , j);
ll l = ((i + j) >> 1) - i + 1;
ll r = j - ((i + j) >> 1) + 1;
//cout << i << " " << l << " " << r << " " << sum_left << " " << sum_right << " " << k << endl;
return l * k - sum_left + sum_right - r * k;
};
ll ans = inf;
for(int i = 0; i < w; ++i){
ans = min(ans, get(i));
}
cout << ans << endl;
}
void input(){
IOS;
int tt;
cin >> tt;
for(int cas = 1; cas <= tt; ++cas){
cout << "Case #" << cas << ": ";
solve();
}
}
int main(){
input();
return 0;
}
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBJT1MgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7IGNv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WyZdKGludCBpICwgaW50IGopewogICAgICAgIHJldHVybiBwcmVmW2pdIC0gKGkgPiAwID8gcHJlZltpIC0gMV0gOiAwKTsKICAgIH07CiAgICBhdXRvIGdldCA9IFsmXShpbnQgaSl7CiAgICAgICAgaW50IGogPSBpICsgdyAtIDE7CiAgICAgICAgaW50IGsgPSBhWyhpICsgaikgPj4gMV07CiAgICAgICAgbGwgc3VtX2xlZnQgPSBnZXRfc3VtKGksIChpICsgaikgPj4gMSk7CiAgICAgICAgbGwgc3VtX3JpZ2h0ID0gZ2V0X3N1bSgoaSArIGopID4+IDEgLCBqKTsKICAgICAgICBsbCBsID0gKChpICsgaikgPj4gMSkgLSBpICsgMTsKICAgICAgICBsbCByID0gaiAtICgoaSArIGopID4+IDEpICsgMTsKICAgICAgICAvL2NvdXQgPDwgaSA8PCAiICIgPDwgbCA8PCAiICIgPDwgciA8PCAiICIgPDwgc3VtX2xlZnQgPDwgIiAiIDw8IHN1bV9yaWdodCA8PCAiICIgPDwgayA8PCBlbmRsOwogICAgICAgIHJldHVybiBsICogayAtIHN1bV9sZWZ0ICsgc3VtX3JpZ2h0IC0gciAqIGs7CiAgICB9OwogICAgbGwgYW5zID0gaW5mOwogICAgZm9yKGludCBpID0gMDsgaSA8IHc7ICsraSl7CiAgICAgICAgYW5zID0gbWluKGFucywgZ2V0KGkpKTsKICAgIH0KICAgIAogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKICAgIAoKfQp2b2lkIGlucHV0KCl7CiAgICBJT1M7CiAgICBpbnQgdHQ7CiAgICBjaW4gPj4gdHQ7CiAgICBmb3IoaW50IGNhcyA9IDE7IGNhcyA8PSB0dDsgKytjYXMpewogICAgICAgIGNvdXQgPDwgIkNhc2UgIyIgPDwgY2FzIDw8ICI6ICI7CiAgICAgICAgc29sdmUoKTsKICAgIH0KfQoKaW50IG1haW4oKXsKICAgIGlucHV0KCk7CiAgICByZXR1cm4gMDsKfSAKLyoKZnJlb3BlbigiaW5wdXQudHh0IiwiciIsc3RkaW4pOwpmcmVvcGVuKCJvdXRwdXQudHh0IiwidyIsc3Rkb3V0KTsKKi8K