#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define print(v) for(auto data : v) cout << data << " "; cout << endl;
using namespace std;
void solve()
{
int n, k; cin >> n >> k;
vector<ll> v(n+1);
for (int i = 1; i <= n; i++)
{
cin >> v[i];
}
int l = 1, r = 1;
ll sum = 0;
ll ans = 2e6 + 5;
while (r <= n)
{
sum += v[r];
if(r-l+1 == k)
{
vector<ll> lu;
ll mx = v[l];
ll mn = mx;
for (int i = 1; i <= n; i++)
{
if(i >= l && i <= r)
{
mx = max(mx, v[i]);
}
else
{
lu.push_back(v[i]);
}
}
ll min_ele;
if(!lu.empty()) min_ele = *min_element(lu.begin(), lu.end());
ll tmp = sum;
if(!lu.empty() && mx > min_ele)
{
tmp -= mx;
tmp += min_ele;
}
ans = min(ans, tmp);
sum -= v[l]; l++;
}
r++;
}
cout << ans << endl;
}
int main ()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t; cin >> t;
while (t--) solve();
return 0;
}