#include<algorithm>
#include<cstdio>
const int M=2e5+5;
int T,n,p,res,a[M],id[M];bool vis[M];long long ans;
inline bool cmp(const int&x,const int&y){
	return a[x]<a[y];
}
signed main(){
	register int i,j,L,R;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&p);res=n-1;ans=0;
		for(i=1;i<=n;++i)scanf("%d",a+i),vis[id[i]=i]=false;
		std::sort(id+1,id+n+1,cmp);
		for(i=1;i<=n;++i){
			if(vis[id[i]])continue;
			if(a[L=R=id[i]]>=p)break;
			while(!(a[L]%a[id[i]])&&L>=1){
				--L;if(vis[L+1])break;
			}
			while(!(a[R]%a[id[i]])&&R<=n){
				++R;if(vis[R-1])break;
			}
			--R;++L;ans+=1ll*(R-L)*a[id[i]];res-=R-L;
			for(j=L;j<=R;++j)vis[j]=true;
		}
		printf("%lld\n",ans+1ll*res*p);
	}
}
