#include<algorithm>
#include<string>
#include<iostream>
#include<iomanip>
#include<queue>
#include<string.h>
#include<set>
#include<map>
#include<utility>
//#define int long long
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const int INF = (1 << 31) - 1;
const int mod = 1e9 + 7;
ll qpow(ll a, ll b) {
	ll res = 1;
	while (a) {
		if (a & 1) {
			res *= b; res %= mod;
		}
		a >>= 1;
		b <<= 1; b %= mod;
	}
	return res;
}
int arr[maxn];
struct node {
	int id, val;
};
node n[maxn];
bool con[maxn];
void work() {
	int N, p; cin >> N >> p;
	memset(con, 0, sizeof(con));
	memset(n, 0, sizeof(n));
	for (int i = 1; i <= N; ++i) { cin >> arr[i]; n[i].val = arr[i]; n[i].id = i; }
	sort(n + 1, n + 1 + N, [](node n1, node n2) {return n1.val < n2.val; });
	ll ans = 0;
	for (int i = 1; i <= N; ++i) {
		if (n[i].val >= p)break;
		else {
			int cur = n[i].id;
			while (cur > 1) {
				if (con[cur-1])break;
				if (arr[cur - 1] % n[i].val == 0) { ans += n[i].val; con[cur - 1] = 1; cur--; }
				else 
					break;
			}
			cur = n[i].id;
			while (cur <= N - 1) {
				if (con[cur])break;
				if (arr[cur + 1] % n[i].val == 0) { ans += n[i].val; con[cur] = 1; cur++; }
				else 
					break;
			}
		}
	}
	for (int i = 1; i < N; ++i) {
		if (!con[i])ans += p;
	}
	cout << ans << '\n';
	return;
}
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t; cin >> t;
	while (t--) {
		work();
	}
}