#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)
{
ll mx = v[l];
for (int i = l; i <= r; i++)
{
mx = max(mx, v[i]);
}
ll mn = mx;
for (int i = 1; i <= n; i++)
{
if(i >= l && i <= r) continue;
mn = min(mn, v[i]);
}
ll tmp = sum;
if(mx > mn)
{
tmp -= mx;
tmp += mn;
}
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;
}