#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;
struct DSU {
vector<int> par, sz;
int N;
DSU() {}
DSU(int N) : N(N) {
sz.resize(N);
fill(sz.begin(), sz.end(), 1);
par.resize(N);
iota(par.begin(), par.end(), 0);
}
void union_sets(int u, int v) {
u = get_parent(u);
v = get_parent(v);
if (u == v) return;
if (sz[u] < sz[v]) swap(u, v);
par[v] = u;
sz[u] += sz[v];
}
bool in_same_set(int u, int v) {
return (get_parent(u) == get_parent(v));
}
int get_parent(int u) {
if (u == par[u]) return u;
par[u] = get_parent(par[u]);
return par[u];
}
int get_size(int u) {
return sz[get_parent(u)];
}
};
vector<ll> primes;
void gen_primes(ll n) {
ll i, j;
vector<bool> s(n+1, 1);
primes.push_back(2);
for (i = 4; i <= n; i += 2) s[i] = 0;
for (i = 3; i*i <= n; i += 2) {
if (!s[i]) continue;
for (j = i*i; j <= n; j += i) s[j] = 0;
}
for (i = 3; i <= n; i += 2) {
if (s[i]) primes.push_back(i);
}
}
int main() {
FAST;
gen_primes(32000);
int tc = 1, ti;
cin >> tc;
for (ti = 1; ti <= tc; ++ti) {
ll n, k, i, j, u, x, curr, ans;
cin >> n >> k;
vector<ll> a(n);
for (i = 0; i < n; ++i) cin >> a[i];
DSU dsu(n);
for (u = 0; u < (int)primes.size(); ++u) {
x = primes[u];
j = -1;
for (i = 0; i < n; ++i) {
if (a[i] % x == 0) {
if (j == -1) j = i;
else dsu.union_sets(j, i);
}
}
}
vector<ll> col(n);
for (i = 0; i < n; ++i) col[i] = dsu.get_parent(i);
vector<vector<ll>> pf(n, vector<ll>(1, 0));
for (i = 0; i < n; ++i) {
pf[col[i]].push_back(a[i]);
}
for (i = 0; i < n; ++i) {
sort(pf[i].begin()+1, pf[i].end());
reverse(pf[i].begin()+1, pf[i].end());
for (j = 1; j < (int)pf[i].size(); ++j) {
pf[i][j] += pf[i][j-1];
}
}
vector<ll> ptr(n, 0);
curr = 0;
auto add = [&](ll col) {
curr -= pf[col][ptr[col]];
ptr[col] += 1;
curr += pf[col][ptr[col]];
};
auto remove = [&](ll col) {
curr -= pf[col][ptr[col]];
ptr[col] -= 1;
curr += pf[col][ptr[col]];
};
for (i = 0; i < k; ++i) add(col[i]);
ans = curr;
for (i = k; i < n; ++i) {
remove(col[i-k]);
add(col[i]);
ans = max(ans, curr);
}
cout << ans << "\n";
}
return 0;
}