#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll gcd_(ll a, ll b) {
return b==0? a : gcd_(b, a%b);
}
void solve() {
ll n, k;
cin >> n >> k;
vector<ll> arr(n);
for (ll i = 0; i < n; i++) {
cin >> arr[i];
}
vector<ll> dp(n + 1, LLONG_MAX);
dp[1] = 0;
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
pq.push({0, 1}); // (cost, index)
while (!pq.empty()) {
pair<ll, ll> topElement = pq.top();
ll currentCost = topElement.first;
ll i = topElement.second;
pq.pop();
if (currentCost > dp[i]) {
continue;
}
//Move to the next position (i + 1)
if (i + 1 <= n) {
ll nextCost = currentCost + k;
if (nextCost < dp[i + 1]) {
dp[i + 1] = nextCost;
pq.push({nextCost, i + 1});
}
}
// Jump to any position j > i
for (ll j = i + 1; j <= n; ++j) {
ll jumpCost = arr[i - 1] / gcd_(arr[i - 1], arr[j - 1]);
ll totalCost = currentCost + jumpCost;
if (totalCost < dp[j]) {
dp[j] = totalCost;
pq.push({totalCost, j});
}
}
}
cout << dp[n] << endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}