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

int getRoot(int N, vector<int> &parent){
    if(parent[N] != N) {
        parent[N] = getRoot(parent[N],parent);
    }
    return parent[N];
}


int main() {
    int T;
    cin>>T;
    while(T--) {
        long long N,P;
        cin>>N>>P;

        vector<long long> ori(N);
        vector<pair<long long,int> > v(N);
        for(int c=0;c<N;c++) {
            cin>>v[c].first;
            ori[c]=v[c].first;
            v[c].second = c;
        }
        vector<int> parent(N);
        for(int c=0;c<N;c++) parent[c]=c;
        sort(v.begin(),v.end());
        long long res = 0;
        for(int c=0;c<N;c++) {
            if(v[c].first > P) {
                break;
            }

            int l = v[c].second;
            int r = v[c].second;
            long long val = v[c].first;
            int ro = getRoot(l,parent);
            if(ro != v[c].second) continue;

            while(l > 0 && ori[l-1]%val == 0) {
                l--;

                int r2 = getRoot(l,parent);
                if(ro==r2) break;
                res += val;

                if(ori[r2] <= val) {
                    parent[ro] = r2;
                    ro=r2;
                } else {
                    parent[r2] = ro;
                }
            }

            while(r+1 < N && ori[r+1]%val == 0) {
                r++;
                int r2 = getRoot(r,parent);
                if(ro==r2) break;
                res += val;

                if(ori[r2] <= val) {
                    parent[ro] = r2;
                    ro=r2;
                } else {
                    parent[r2] = ro;
                }
            }

        }

        set<int> roots;
        for(int c=0;c<parent.size();c++) {
            roots.insert(getRoot(c,parent));
        }
        res += (roots.size()-1)*P;
        cout<<res<<endl;
    }
}
