#include<bits/stdc++.h>
#include <queue>
#include <numeric>
#include <limits>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
vector<int>a(n);
for(int i=0; i<n; i++){
cin>>a[i];
}
vector<int> m(n, numeric_limits<int>::max());
m[0]=0;
using pii = pair<int, int>;
priority_queue<pii,vector<pii>,greater<pii>>pq;
pq.push({0, 0});
while (!pq.empty()){
int cost=pq.top().first;
int index=pq.top().second;
pq.pop();
if (cost>m[index])
continue;
if (index+1<n){
int new_cost=cost+k;
if(new_cost<m[index+1]){
m[index+1]=new_cost;
pq.push({new_cost, index+1});
}
}
for(int j=index+1; j<n; j++){
int move_cost=a[index]/gcd(a[index], a[j]);
int new_cost=cost+move_cost;
if(new_cost<m[j]){
m[j]=new_cost;
pq.push({new_cost, j});
}
}
}
cout<<m[n-1]<<endl;
}
}