#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;
for (ll i =1; i<=n; i++) {
if(i+1<=n){
dp[i+1]=min(dp[i+1],dp[i]+k);
}
for(ll j=i+1; j<=n; j++){
ll cost=arr[i-1]/gcd_(arr[i-1],arr[j-1]);
dp[j]=min(dp[j],dp[i]+cost);
}
}
cout << dp[n] << endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}