#include <bits/stdc++.h>

using namespace std;

int t,n,p,b[202020],f[202020];
long long ans;

struct node
{
    int val,id;
}a[202020];

int cmp(node &a1,node &a2)
{
    return a1.val < a2.val;
}

int find_(int x)
{
    return x == f[x] ? x : f[x] = find_(f[x]);
}

int main()
{
    cin >> t ;
    while(t--){
        cin >> n >> p ;
        ans = 0;
        for(int i = 1 ; i <= n ; ++i){
            cin >> a[i].val ;
            a[i].id = f[i] = i;
            b[i] = a[i].val;
        }
        sort(a+1,a+1+n,cmp);
        int num = 0;
        for(int i = 1 ; i <= n ; ++i){
            if(a[i].val > p)break;
            for(int l = a[i].id-1 ; l >= 1 ; --l){
                if(b[l] % a[i].val != 0)break;
                int fl = find_(l);
                int fr = find_(a[i].id);
                if(fl == fr)break;
                ans += (a[i].val);
                f[fl] = fr;
                ++num;
            }
            for(int r = a[i].id+1 ; r <= n ; ++r){
                if(b[r] % a[i].val != 0)break;
                int fl = find_(r);
                int fr = find_(a[i].id);
                if(fl == fr)break;
                ans += (a[i].val);
                f[fl] = fr;
                ++num;
            }
        }
        ans += (long long)p*(n-1-num);
        cout << ans << endl ;
    }
    return 0;
}
