#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];
}
int64_t res = 0;
for (int i = 0; i <= n - k; i++) {
multiset<int> S;
for (int j = i; j < i + k; j++) {
S.insert(a[j]);
}
vector<int> taken(n, 0);
int64_t sum = 0;
for (auto it : S) {
pair<int, int> who = {it, i};
for (int j = i - 1; ~j; --j) {
if (!taken[j]) {
if (__gcd(it, a[j]) > 1) {
if (a[j] > who.first) {
who.first = a[j];
who.second = j;
}
}
}
}
for (int j = i + 1; j < n; j++) {
if (!taken[j]) {
if (__gcd(it, a[j]) > 1) {
if (a[j] > who.first) {
who.first = a[j];
who.second = j;
}
}
}
}
sum += who.first;
taken[who.second] = 1;
}
res = max(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;
}