#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;

signed main() {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--) {
		int n, p;
		cin >> n >> p;
		vector<int>a(n), f(n);
		vector<pair<int, int>>b;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			b.emplace_back(a[i], i);
		}
		sort(b.begin(), b.end());
		int ans = 0;
		for (int i = 0; i < n; i++) if (!f[b[i].second]) {
			int x = b[i].second, v = b[i].first;
			f[x] = v;
			int cnt = 0;
			for (int j = x + 1; j < n && a[j] % v == 0 && !f[j]; j++)
				f[j] = v, cnt++;
			for (int j = x - 1; j >= 0 && a[j] % v == 0 && !f[j]; j--)
				f[j] = v, cnt++;
			ans += cnt * min(p, v);
		}
		for (int i = 1; i < n; i++) if (f[i] != f[i - 1]) {
			if (a[i] % f[i - 1] == 0) ans += min(p, f[i - 1]);
			else if (a[i - 1] % f[i] == 0) ans += min(p, f[i]);
			else ans += p;
		}
		cout << ans << '\n';
	}
	return 0;
}