#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ld long double

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = 2e5 + 10, MOD = 1e9 + 7;
int funk[4 * N], a[N];

int gcd(int a, int b){
    if (b == 0){
        return a;
    }
    else{
        return gcd(b, a % b);
    }
}

void build(int v, int l, int r){
    if (l == r){
        funk[v] = a[l];
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m), build(2 * v + 1, m + 1, r);
    if (max(funk[v * 2], funk[v * 2 + 1]) == MOD) funk[v] = min(funk[v * 2], funk[v * 2 + 1]);
    else funk[v] = gcd(funk[v * 2], funk[v * 2 + 1]);
}

int get(int v, int tl, int tr, int l, int r){
    if (l > r) return MOD;
    if (tl == l && tr == r) return funk[v];
    int tm = (tl + tr) / 2;
    int p = get(2 * v, tl, tm, l, min(r, tm)), pp = get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
    if (max(p, pp) == MOD){
        return min(p, pp);
    }
    else{
        return gcd(p, pp);
    }
}

void solve(){
    long long n, p;
    cin >> n >> p;
    for (int i = 0; i < 4 * n; i++) funk[i] = MOD;
    vector<pair<int,int>> u;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        u.pb({a[i], i});
    }
    build(1, 0, n - 1);
    sort(u.begin(), u.end());
    set<int> st;
    for (int i = 0; i < n - 1; i++){
        st.insert(i);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++){
        if (u[i].first >= p){
            continue;
        }
        int l = -1, r = u[i].second;
        while(r - l > 1){
            int mid = (r + l) / 2;
            int p = get(1, 0, n - 1, mid, u[i].second);
            if (p == u[i].first){
                r = mid;
            }
            else{
                l = mid;
            }
        }
        int f = r;
        l = u[i].second, r = n;
        while(r - l > 1){
            int mid = (r + l) / 2;
            int p = get(1, 0, n - 1, u[i].second, mid);
            if (p == u[i].first){
                l = mid;
            }
            else{
                r = mid;
            }
        }
        while(st.size() > 0){
            if (st.lower_bound(f) == st.end()) break;
            auto v = *st.lower_bound(f);
            if (v < l){
                st.erase(v);
                ans += u[i].first;
            }
            else{
                break;
            }
        }
    }
    ans += (long long)p * st.size();
    cout << ans << endl;
}

int32_t main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
