#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll T, n, p, ans;
ll a[200003];
ll b[200003];
ll e[200003];
vector<ll> vis[200003];

// ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}

int main()
{
	scanf("%lld", &T);
	while(T--)
	{
		scanf("%lld%lld", &n, &p);
		for(ll i = 1; i <= n; ++i)
		{
			a[i] = 0; b[i] = 0; e[i] = 1e9;
			vis[i].clear();
		}
		for(ll i = 1; i <= n; ++i)
		{
			scanf("%lld", &a[i]);
			b[i] = a[i];
			e[i] = p;
		}
		sort(b + 1, b + n + 1);
		ll cnt = unique(b + 1, b + n + 1) - b - 1;
		for(ll i = 1; i <= n; ++i)
		{
			ll tmp = lower_bound(b + 1, b + cnt + 1, a[i]) - b;
			vis[tmp].push_back(i);
		}
		for(ll i = 1; i <= cnt && b[i] < p; ++i)
		{
			for(ll j = 0; j < vis[i].size(); ++j)
			{
				for(ll k = vis[i][j] + 1; k <= n; ++k)
				{
					if(e[k] <= b[i]) break;
					if(a[k] % b[i]) break;
					e[k] = b[i];
				}
				for(ll k = vis[i][j]; k >= 2; --k)
				{
					if(e[k] <= b[i]) break;
					if(a[k - 1] % b[i]) break;
					e[k] = b[i];
				}
			}
		}
		/*
		for(ll i = 1; i <= n; ++i)
			printf("%lld ", e[i]);
		puts("");
		*/
		ans = 0;
		for(ll i = 2; i <= n; ++i)
			ans += e[i];
		printf("%lld\n", ans);
	}
    return 0;
}
