#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, b) for (long long int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+9;
struct num{
	ll val,mi,la,pos;
}a[200010];
ll b[200010];
bool com(num a,num b)
{
	return a.val < b.val;
}
set <ll> se;
int main()
{
	int t;cin>>t;
	while(t--)
	{
		ll n,p;cin>>n>>p;se.clear();
		rep (i,1,1+n) scanf("%lld",&a[i].val),b[i] = a[i].val,a[i].la = 0,a[i].pos = i;
		ll ans = 0;
	//	a[0].mi = INF;int j = 1;
		sort (a+1,a+n+1,com);
		ll falg = 0;
		rep (j,1,n)
		{
			if (se.find(a[j].pos) ==  se.end())
			{
				ll L = a[j].pos; ll R = a[j].pos;
				rep (i,a[j].pos+1,n+1) 
				{
					while (i < n+1&&b[i] % a[j].val == 0&&se.find(i) == se.end()) 
						R++,se.insert(i),i++;
					if (b[i] % a[j].val == 0&&se.find(i) != se.end()) falg --,ans += min(p,a[j].val);
					break;
				}
					
				for (ll i = a[j].pos-1;;i--)
				{
					while (i >= 1&&b[i] % a[j].val == 0&&se.find(i) == se.end()) 
						L--,se.insert(i),i--;
					if (b[i] % a[j].val == 0&&se.find(i) != se.end()) falg --,ans += min(p,a[j].val);
					break;
				}
					
				if (L != R)
				{
					se.insert(a[j].pos);falg ++;
					ans += (R - L) * min(p,a[j].val);
				}
			}
		}
		
		rep (i,1,n+1)
			if (se.find(a[i].pos) ==  se.end()) falg++;
	//	cout<<falg<<'\n'; 
		ans += (falg-1)*p;
		cout<<ans<<'\n';
	}
}
