#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int getint()
{
	char ch;int ans=1,f=1;
	do{ch=getchar();}while(ch!='-'&&(ch<'0'||ch>'9'));
	if(ch=='-')f=1;else ans=ch-'0';
	while(isdigit(ch=getchar())){ans=ans*10+ch-'0';}
	return ans*f;
}
struct N
{
	long long v,id;
}a[200001];
long long ans[200001],b[200001];
bool cmp(const N& x,const N& y)
{
	return x.v<y.v;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n=getint(),k;
		k=getint();
		for(int i=1;i<=n;i++)
		{
			a[i].v=b[i]=getint();
			a[i].id=i;
			ans[i]=k;
		}
		sort(a+1,a+1+n,cmp);
		for(int i=1;i<=n;i++)
		{
			if(a[i].v>=k)  break;
			long long cnt=1;
			while(a[i].id+cnt<=n&&b[a[i].id+cnt]%a[i].v==0&&ans[a[i].id+cnt-1]==k)
			  ans[a[i].id-1+cnt++]=a[i].v;
//			if(cnt>1)  ans[a[i].id]=ans[a[i].id]==k? a[i].v:ans[a[i].id];
			cnt=1; 
			while(a[i].id-cnt&&b[a[i].id-cnt]%a[i].v==0&&ans[a[i].id-cnt]==k)
			  ans[a[i].id-cnt++]=a[i].v;
//			if(cnt>1)  ans[a[i].id]=ans[a[i].id]==k? a[i].v:ans[a[i].id];
		}
		long long Ans=0;
//		for(int i=1;i<=n;i++)  cout<<ans[i]<<" ";cout<<"\n";  
//		sort(ans+1,ans+1+n);
		ans[0]=ans[1];
		for(int i=1;i<n;i++)
		  Ans+=ans[i];
		cout<<Ans<<"\n";
	}
 } 
