#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

void solve() {
    int n, c;
    cin >> n >> c;

    vector<int> a(n);

    int k{};

    for(int i{}; i < n; ++i){
        cin >> a[i];
        if(a[i] < c) k++;
    }

    sort(a.begin(), a.end());

    ll score{};

    // 2 cases : k <= n/2
    //           k > n/2

    if(k > n/2){
        for(int i{n/2}; i < n; ++i){
            score += (a[i]-c);
        }
    }

    else{
        for(int i{k}; i < n; ++i){
            score += (a[i] - c);
        }
    }

    cout << score << endl;


}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
 