#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve(int cs) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
unordered_map<int, vector<pair<int, int>>> who;
for (int i = 0; i < n; i++) {
for (int j = i - 1; j >= 0; j--) {
if (a[j] > a[i]) {
if (__gcd(a[i], a[j]) > 1) {
who[a[i]].push_back({a[j], j});
}
}
}
for (int j = i + 1; j < n; j++) {
if (a[j] > a[i]) {
if (__gcd(a[i], a[j]) > 1) {
who[a[i]].push_back({a[j], j});
}
}
}
}
for (auto &[_, v] : who) {
sort(v.rbegin(), v.rend());
}
int64_t res = 0;
multiset<int> S;
for (int i = 0; i < k; i++) {
S.insert(a[i]);
}
for (int i = k - 1; i < n; i++) {
if (i >= k) {
S.insert(a[i]);
S.erase(S.find(a[i - k]));
}
int64_t sum = 0;
pair<int, int> range = {i - k, i};
unordered_map<int, bool> taken;
for (auto &it : S) {
int got = it;
for (auto &[val, id] : who[it]) {
if (id > range.second || id < range.first) {
if (!taken[id]) {
got = val;
taken[id] = true;
break;
}
}
}
sum += got;
}
if (sum > res) res = sum;
}
cout << res << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
cin >> tc;
for (int cs = 1; cs <= tc; cs++) {
solve(cs);
}
return 0;
}