#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
using ll = long long;
#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;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
ll ans = 1e17, sum = 0, ind = -1, big = v[0], curr_big = v[0];
for (int i = 1; i <= n; i++) {
if (i > k) {
sum -= v[i - k];
// cout << sum << ' ';
sum += v[i];
// cout << sum << ' ';
if (sum < ans) {
ans = sum;
ind = i;
// cout << big << ' ';
// if (big < v[i])
// big = v[i];
}
if (big < v[i])
big = v[i];
}
else {
sum += v[i];
if (big < v[i])
big = v[i];
// cout << big << ' ';
ind = i;
ans = sum;
//cout << sum << ' ';
}
}
// cout << ans << ' ' << big << '\n';
int mn = 1e9;
for (int i = 1; i <= n; i++) {
if (i > min(ind, abs(k - ind)) and i <= max(ind, abs(k - ind)))
continue;
if (mn > v[i])
mn = v[i];
}
// cout << mn << ' ' << big << '\n';
ans -= big;
ans += mn;
cout << ans << '\n';
// cout << ind << '\n';
}
return 0;
}