#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define trace(x) cout << #x << ": " << x << endl
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--)
{
int n,k;
cin>>n>>k;
int a[n];
vector<int> b,an;
int sum = 0;
for(int i = 0; i < n; i++)
{
cin>>a[i];
sum+=a[i];
b.push_back(sum);
}
int ans = INT_MAX;
for(int i = 0; i+k-1 < b.size(); i++)
{
int x = i+k-1;
int subsum;
if(i==0)
subsum = b[x];
else if(i>0&&x<b.size()-1)
subsum = b[x]-b[i-1];
else if(x == b.size()-1)
subsum = b[x]-b[i-1];
ans = subsum;
int mx=a[i];
for(int j = i ; j <= x ;j++){
mx = max(mx,a[j]);
}
int mn = mx;
for(int j = i-1 ; j >=0 ; j--){
mn = min(mn,a[j]);
}
for(int j = x+1 ; j<n ;j++){
mn = min(mn,a[j]);
}
//cout<<ans<<" "<<mx<<" "<<mn<<endl;
ans -= mx;
ans+= mn;
an.push_back(ans);
}
sort(an.begin(),an.end());
cout<<an[0]<<endl;
}
return 0;
}