#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
int t,n,p;
int a[MAX<<1];
int main(){FAST;
cin>>t;
while(t--){
  cin>>n>>p;
  for(int i=1;i<=n;++i){
    cin>>a[i];
  }
  vector<pair<int,int> >v;
  for(int i=1;i<=n;++i){
    v.push_back(make_pair(a[i],i));
  }
  sort(all(v));
  vector<int>vis(n+1);
  ll ans = 0;
  int edges = n-1;
  for(const auto& it:v){
    int idx = it.second;
    int val = it.first;
    if(val>=p)break;
    if(vis[idx])continue;
    int nodes = 1;
    vis[idx] = 1;
    int cur = idx+1;
    while(cur<=n and a[cur]%val == 0){
      ++nodes;
      if(vis[cur])break;
      vis[cur] = 1;
      ++cur;
    }
    cur = idx-1;
    while(cur>=1 and a[cur]%val == 0){
      ++nodes;
      if(vis[cur])break;
      vis[cur] = 1;
      --cur;
    }
    // cout<<val<<' '<<idx<<' '<<nodes<<'\n';
    ans+=1LL*(nodes-1)*val;
    edges-=nodes-1;
  }
  ans+=1LL*edges*p;
  cout<<ans<<'\n';
}
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */