#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;
cin >> n >> k;
for (i = 0; i < MX; ++i) dis[i] = INF;
vector<int> a(n), dp(n);
for (i = 0; i < n; ++i) cin >> a[i];
dp[i] = 0;
for (int d : divs[a[0]]) {
dis[d] = a[0]/d;
}
for (i = 1; i < n; ++i) {
dp[i] = dp[i-1] + k;
for (int d : divs[a[i]]) {
dp[i] = min(dp[i], dis[d]);
}
for (int d : divs[a[i]]) {
dis[d] = min(dis[d], dp[i] + a[i]/d);
}
}
cout << dp[n-1] << "\n";
}
return 0;
}