#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define deb(x) cout << #x << " " << x << endl;
#define mod 1000000007
#define mod2 998244353
#define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define endl "\n"
const ll INF = 1e18;
const ll NEGINF = -1 * INF;

/*NOTES: Take care of ll vs int
         Never use an iterator after erasing it.
*/

void solve()
{
    ll n, p;
    cin >> n >> p;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<array<ll, 2>> arr;
    for (int i = 0; i < n; i++)
    {
        arr.push_back({a[i], i});
    }
    sort(arr.begin(), arr.end());
    vector<bool> is_connected(n, false);
    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        int currVal = arr[i][0];
        int currInd = arr[i][1];
        if (currVal >= p)
        {
            break;
        }
        //gcd of elements is currVal, minimum of elements is currVal
        //move left
        while (currInd > 0)
        {
            if (is_connected[currInd - 1])
            {
                break;
            }
            if (a[currInd - 1] % currVal == 0)
            {
                is_connected[currInd - 1] = true;
                ans += currVal;
                currInd--;
            }
            else
            {
                break;
            }
        }
        currInd = arr[i][1];
        //gcd of elements is currVal, minimum of elements is currVal
        //move right
        while (currInd < n - 1)
        {
            if (is_connected[currInd])
            {
                break;
            }
            if (a[currInd + 1] % currVal == 0)
            {
                is_connected[currInd] = true;
                ans += currVal;
                currInd++;
            }
            else
            {
                break;
            }
        }
    }

    for (int i = 0; i < n - 1; i++)
    {
        if (!is_connected[i])
        {
            ans += p;
        }
    }

    cout << ans << endl;
}

int main()
{
    fast;
#ifndef ONLINE_JUDGE
    freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin);
    freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout);
#endif
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    //cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
    return 0;
}