#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PLL pair<ll,ll>
#define mod 1000000007
#define mx 200005
#define FILE freopen("input.txt","r",stdin)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll a[mx];

int main()
{
    fastio
    ll t,n,p,x,id;
    cin>>t;

    while(t--){
        cin>>n>>p;
        vector<PLL>v;

        for(ll i = 1;i<=n;i++){
            cin>>x;
            a[i] = x;
            v.push_back({x, i});
        }

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

        map<ll,ll>mp;
        ll need = n-1;
        ll ans = 0;

        for(ll i = 0;i<v.size() && v[i].first<=p;i++){
            if(mp[v[i].second]) continue;

            mp[v[i].second] = 1;

            id = v[i].second + 1;

            while(a[id]%v[i].first==0 && !mp[id] && id<=n){
                need--;
                ans+=v[i].first;
                //cout<<ans<<endl;
                mp[id] = 1;
                id++;
            }

            if(id-1!=v[i].second) mp[id-1] = 0;

            id = v[i].second - 1;

            while(a[id]%v[i].first==0 && !mp[id] && id>=1){
                need--;
                ans+=v[i].first;
                //cout<<ans<<endl;
                mp[id] = 1;
                id--;
            }

            if(id+1!=v[i].second) mp[id+1] = 0;
        }

        ans+=(need*p);

        cout<<ans<<endl;
    }

    return 0;
}
