#include<bits/stdc++.h>
using namespace std;
#define int long long
#define bug(a) cout << #a << " : " << a << '\n';
void solve(int cs){
int n,k;cin >> n >> k;
vector<int>arr(n);
vector<int>prefix(n+1,0);
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
}
if(k == 1){
int ans = *min_element(arr.begin(),arr.end());
cout << ans << '\n';
return;
}
for (int i = 1; i <= n; ++i)
{
prefix[i] = prefix[i-1] + arr[i -1];
}
int mn = INT_MAX;
int i = 1;int j = i+k-1;
int x = 0,y = 0;
for(; j < n ;i ++,j ++){
int sub = prefix[j] - prefix[i-1];
if(mn > sub){
mn = sub;
x = i-1;
y = j-1;
}
}
int maxi = INT_MIN;
for(int i = x;i <= y;++i)
{
maxi = max(arr[i],maxi);
}
int mini = INT_MAX;
for(int i = 0;i < n;++i)
{
if(i >= x and i <= y) continue;
mini = min(arr[i],mini);
}
int mn_d = mn;
mn_d -= maxi;
mn_d += mini;
if(mn_d < mn) cout << mn_d << '\n';
else cout << mn << '\n';
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t; cin>>t;
int cs = 0;
while(t--){
solve(++cs);
}
return 0;
}