#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
struct node
{
	ll val;
	int id;
	bool operator <(node b){
		return val<b.val;
	}
}fbk[maxn];
bool vis[maxn];
ll w[maxn];
bool cmp(node a,node b){
	return a.val<b.val;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,p;
		cin>>n>>p;
		int i,j,k;
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&w[i]);
			fbk[i].val=w[i];
			fbk[i].id=i;
			vis[i]=0;
		}
		ll ans=1ll*(n-1)*p;
		sort(fbk+1,fbk+n+1,cmp);
		for(i=1;i<=n;i++)
		{
			if(fbk[i].val>=p) break;
			ll t=fbk[i].val;
			int id=fbk[i].id;
			int l=id,r=id;
			while(l>1&&(!vis[l-1])&&w[l-1]%t==0) l--;
			while(r<n&&(!vis[r])&&w[r+1]%t==0) r++;
			if(l!=r) 
			{
				for(j=l;j<=r-1;j++)
					vis[j]=1;
			}
			ans-=(r-l)*(p-t);
		}
		cout<<ans<<endl;
	}
	return 0;
} 
	   	 	   		 	    				  	  				