//Classic
//g++ -std=c++17 -O2 -Wall a.cpp -o test
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define vb vector<bool>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug2(x,y) cout<<"This side ----> "<<#x<<" -> "<<x<<" | "<<#y<<" -> "<<y<<endl;
#define debug(x) cout<<"This side    ----> "<<#x<<" -> "<<x<<endl
//#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
//#define ao(a, n) {for (int ele = 0; ele < (n); ele++) {cout << a[ele]<<" "; } cout << '\n';}
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define mint map<int,int>
#define mall map<ll,ll>
#define ciN cin
#define g(a,s) get<a>(s)
#define tin tuple<ll,ll,ll>
#define ter(x,y,z) ((x)?y:z)
bool isGoogles = 0;
const ll maxn = 2e5 + 10;
const ll max_val = 2e5 + 10;
const ll mod = 1000000007;
const ll bits = 10;
ll caseNumber = 1;
////////////////////////////////////////////////////////////////
ll gcd (ll a, ll b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}
/*

*/


void jabru() {
	ll n, p; cin >> n >> p;
	vl v(n);
	multiset<pl>s;
	vb vis(n, 0);
	For(i, 0, n) {
		cin >> v[i];
		s.insert(mp(v[i], i));
	}
	ll ans = 0;
	ll added = 0;
	for (auto x : s) {
		//	debug(x.F);
		if (x.F >= p) {
			//		debug("OK");
			break;
		}
		if (added == n - 1)break;
		ll ind = x.S, val = x.F;
		bool flag = 1;
		ll curr = ind - 1;
		ll now = x.F;
		while (curr > -1 && flag) {
			if (vis[curr])break;
			if (v[curr] % x.F == 0) {
				vis[curr] = 1;// vis[ind] = 1;
				ans += x.F;
				added++;
				curr--;
			}
			else {
				break;
			}
		}
		curr = ind + 1; flag = 1;
		now = x.F;
		while (curr < n && flag) {
			if (vis[curr - 1])break;
			if (v[curr] % x.F == 0) {
				vis[curr - 1] = 1; // vis[ind] = 1;
				ans += x.F; curr++;
				added++;
			} else break;
		}
	}
	for (int i = 0; i < n - 1; i++) {
		if (!vis[i])ans += p;
	}
	cout << ans << endl;



}
bool TestCase = 1;


//////////////////////////////////////////////////////////////////




int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t;
	t = 1;
	if (TestCase) {
		cin >> t;
	}
	while (t--) {
		if (isGoogles) {cout << "Case #" << caseNumber << ": ";} caseNumber++;
		jabru();
	}
	return 0;
}