#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;
const int INF = 1'000'000'000;
const int MX = 200005;
vector<int> divs[MX];
int dis[MX];
void pre() {
int i, j;
for (i = 1; i < MX; ++i) {
for (j = i; j < MX; j += i) divs[j].push_back(i);
}
}
int main() {
FAST;
pre();
int tc = 1, ti;
cin >> tc;
for (ti = 1; ti <= tc; ++ti) {
int n, k, i, x, ans;
cin >> n >> k;
for (i = 0; i < MX; ++i) dis[i] = INF;
vector<int> a(n);
for (i = 0; i < n; ++i) cin >> a[i];
dis[a[0]] = 0;
for (i = 0; i < n; ++i) {
x = a[i];
for (int d : divs[x]) {
dis[x] = min(dis[x], dis[d]);
}
for (int d : divs[x]) {
dis[d] = min(dis[d], dis[x] + x/d);
}
}
ans = (n-1) * k;
if (n == 1) {
ans = 0;
} else if (a[n-1] % a[0] == 0) {
ans = 1;
} else {
for (i = 0; i < n; ++i) {
ans = min(ans, max(dis[a[i]], 1) + (n-i-1) * k);
}
}
cout << ans << "\n";
}
return 0;
}