#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define bug(a) cout << #a << " : " << a << endl;
void solve(){
int n, k; cin >> n >> k;
vector<ll> v(n + 1);
for(int i = 1; i <= n; i++) cin >> v[i];
deque<int> dq;
ll sum = 0, ans = 1e18;
int l = 0, r = 0;
for(int i = 1; i <= k; i++){
dq.push_back(v[i]);
sum += v[i];
}
ans = sum;
//bug(sum)
l = 1, r = k;
for(int i = k + 1; i <= n; i++){
sum -= dq.front();
dq.pop_front();
sum += v[i];
dq.push_back(v[i]);
if ( sum < ans ) {
ans = sum;
r = i;
l = i - k + 1;
}
}
//bug(ans)
//cout << l << ' ' << r << '\n';
ll mn = 1e18, mx = -1e18;
for(int i =1; i <= n; i++){
if ( i >= l and i <= r ) {
mx = max(mx, v[i]);
}
else{
mn = min(mn, v[i]);
}
}
//cout << mx << ' ' << mn << '\n';
if ( mn < mx ) {
ans -= mx;
//bug(ans)
ans += mn;
}
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc = 1, cs = 0;
cin >> tc;
while(tc--){
//cout << "Case # " << ++cs << ": " ;
solve();
}
}