#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define max_ele(v) *max_element(v.begin(), v.end())
#define min_ele(v) *min_element(v.begin(), v.end())
#define sort_asc(v) sort(v.begin(), v.end())
#define sort_dec(v) sort((v).begin(), (v).end(), greater<>())
#define Reverse(v) reverse(v.begin(), v.end())
#define pb push_back
#define ppb pop_back()
#define cinall(v) \
for (auto &&it : v) \
cin >> it
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define runfaster \
ios_base::sync_with_stdio(false); \
cin.tie(0);
void solucionar()
{
// int n; cin>>n;
int n, k, sum = 0;
cin >> n >> k;
int arr[n];
vector<int> v;
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
}
if (k == n)
{
for (int i = 0; i < n; ++i)
{
sum += arr[i];
}
cout << sum << endl;
return;
}
for (int i = 0; i < k; ++i)
{
sum += arr[i];
}
v.pb(sum);
int f = 0;
for (int i = k; i < n; i++)
{
sum += arr[i];
sum -= arr[f];
v.pb(sum);
f++;
}
int min_ele = v[0], min_ind = 0;
for (int i = 1; i < v.size(); i++)
{
if (v[i] < min_ele)
{
min_ele = v[i];
min_ind = i;
}
}
int max_ele = arr[min_ind], right_min = 100001, left_min = 100001;
for (int i = min_ind + 1; i < min_ind + k; i++)
{
if (arr[i] > max_ele)
{
max_ele = arr[i];
}
}
for (int i = min_ind + k; i < n; i++)
{
if (arr[i] < right_min)
{
right_min = arr[i];
}
}
for (int i = 0; i < min_ind; i++)
{
// left_e = true;
if (arr[i] < left_min)
{
left_min = arr[i];
}
}
int mini = min(left_min, right_min);
if (mini < max_ele)
{
int result = min_ele - max_ele + mini;
cout << result << endl;
return;
}
else{
cout<<min_ele<<endl;
}
}
int main()
{
runfaster
int tests;
cin >> tests;
while (tests-- > 0)
solucionar();
return 0;
}