#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define swap(a,b) (a^=b^=a^=b)
#define ll long long int
#define ull unsigned long long int
#define uint unsigned int
#define format(a) memset(a,0,sizeof(a))
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define dec(x,y,z) for(int x=y;x>=z;x--)
#define mst(x) memset(x,0,sizeof(x))
const int maxn=2e5+20;
inline int read()
{
    int ans=0;
    char last=' ',ch=getchar();
    while(ch<'0'|ch>'9')last=ch,ch=getchar();
    while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    if(last=='-')ans=-ans;
    return ans;
}
int fa[maxn],a[maxn];
int n,m,p,cnt=0;
ll ans=0;
struct aa
{
    int idx;

};
bool operator<(const aa &A,const aa &B)
{
    return a[A.idx]>a[B.idx];
}

int findfa(int x)
{
    if(x==fa[x])return x;
    return fa[x]=findfa(fa[x]);
}
void mer(int x,int y)
{
    fa[findfa(x)]=findfa(y);
}
priority_queue<aa>q;
void solve()
{
    while(!q.empty())q.pop();
    ans=0,cnt=0;
    n=read(),p=read();
    rep(i,1,n)a[i]=read(),fa[i]=i;
    rep(i,1,n)q.push(aa{i});
    while(!q.empty())
    {
        int x=q.top().idx;q.pop();
        if(a[x]>=p)break;
        rep(i,x+1,n)
        {
            if(a[i]%a[x]!=0||findfa(i)==findfa(x))break;
            mer(i,x);
            ans+=a[x],cnt++;
        }
        dec(i,x-1,1)
        {
            if(a[i]%a[x]!=0||findfa(i)==findfa(x))break;
            mer(i,x);
            ans+=a[x],cnt++;
        }
    }
    ans+=1ll*p*(n-1-cnt);
    cout<<ans<<"\n";
}
int main()
{
    int t=read();
    while(t--)solve();
    return 0;
}
/*
1
4 5
5 2 4 9

15
*/
