/*
 * CM 	= April
 * M 	= May
 * IM 	= July
 * GM 	= September
 * IGM	= December
*/
 
#include <bits/stdc++.h>
 
#define F first
#define S second
 
#define pb push_back
#define mp make_pair
 
typedef long long int lli;
 
#define pll pair<lli, lli>
#define pil pair<int, lli>
#define pli pair<lli, int>
#define pii pair<int, int>
#define pdd pair<double, double>
 
#define vi vector<int>
#define vl vector<lli>
#define pq priority_queue
 
#define end end
#define beg begin
#define ub upper_bound
#define lb lower_bound
 
#define dmx(x, y) x = max(x, y)
#define dmn(x, y) x = min(x, y)
 
using namespace std;
 
void setIO(string str, bool dbg) {
	ios_base::sync_with_stdio(0);
 
	cin.tie(nullptr);
	cout.tie(nullptr);
 
	if (!dbg) {
		freopen((str + ".in").c_str(), "r", stdin);
		freopen((str + ".out").c_str(), "w", stdout);
	}
}
 
const int MAX = 3e5 + 5;
const int LEN = 5e4 + 5;
const int LVL = 2e1 + 0;
const lli MOD = 1e9 + 7;
const lli INF = 9e17;
 
int xyz = 1; // test cases
 
int n, p;
 
int arr[MAX];
int ord[MAX];
int ids[MAX];
 
int fnd(int x) {
	if (x == ids[x])
		return x;
	return ids[x] = fnd(ids[x]);
}
 
void unn(int a, int b) {
	a = fnd(a);
	b = fnd(b);
	ids[b] = a;
}
 
bool cmp(int a, int b) {
	return arr[a] < arr[b];
}
 
void pre() {
 
}
 
void run() {
	cin >> n >> p;
 
	for (int i = 1; i <= n; i++) ord[i] = ids[i] = i;
 
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	
	sort(ord + 1, ord + 1 + n, cmp);
 
	int vst = 0;
	lli ans = 0;
	for (int i = 1; i <= n; i++) {
		int idx = ord[i];
 
		if (arr[idx] >= p) break;
 
		//cout << idx << ": " << arr[idx] << " " << vst << "\n";
		
		if (fnd(idx) != idx) continue;
 
		for (int j = idx - 1; j >= 1; j--) {
			if (arr[j] % arr[idx]) break;
			if (fnd(j) != j && fnd(j) != idx) {
				unn(idx, j), ans += arr[idx], vst++;
				break;
			}
			unn(idx, j), ans += arr[idx], vst++;
		}
		for (int j = idx + 1; j <= n; j++) {
			if (arr[j] % arr[idx]) break;
			if (fnd(j) != j && fnd(j) != idx) {
				unn(idx, j), ans += arr[idx], vst++;
				break;
			}
			unn(idx, j), ans += arr[idx], vst++;
		}
	}
 
	ans += 1ll * p * (n - vst - 1);
 
	cout << ans << "\n";
}
 
int main() {
	setIO("", 1);
 
	pre();
 
	cin >> xyz;
	while (xyz--) run();
 
	return 0;
}