/*
* Copyright (c) 2024 Emon Thakur
* All rights reserved.
*/
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve()
{
int n,k; cin>>n>>k;
vector<int>a(n);
for(int i=0;i<n;i++) cin>>a[i];
vector<vector<int>> l(n,vector<int>(n)),r(n,vector<int>(n));
int best;
for(int i=0;i<n-1;i++)
{
best = a[i];
//if(a[i]==1) continue;
for(int j=n-1;j>i;j--)
{
if(__gcd(a[i],a[j])>1)
{
best = max(best,a[j]);
}
r[i][j-i] = best;
}
}
for(int i=1;i<n;i++)
{
best = a[i];
for(int j=0;j<i;j++)
{
if(__gcd(a[i],a[j])>1)
{
best = max(best,a[j]);
}
l[i][i-j]=best;
}
}
/*for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++) cout<<l[i][j]<<" ";
cout<<endl;
}*/
long long sum=0,ans=0;
for(int i=0;i<=n-k;i++)
{
sum = 0;
for(int j=0;j<k;j++)
{
sum += max({a[i],l[i+j][j+1],r[i+j][k-j]});
}
ans = max(ans,sum);
}
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
int t; cin>>t; while(t--) solve();
}