#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define f(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl '\n'
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define ANS cout<<ans<<endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
ll gcd(ll a, ll b) {return __gcd(a,b);}
ll lcm(ll a, ll b) {return a* (b/gcd(a,b));}
const int m=1e9+7;
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = (res * a)%m;
a = (a * a)%m;
b >>= 1;
}
return res;
}
bool subseq(string a,string b)
{
ll x=a.size();
ll y=b.size();
if(x>y)return 0;
ll i = 0, j = 0;
while (i < x && j < y ){
if (a[i] == b[j])i++;
j++;
}
return i==x;
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll t;cin>>t;while(t--)
{
ll n;cin>>n;
ll k;cin>>k;
ll a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
ll ans=INT_MAX;
ll sum=0;
for(int i=0;i<k;i++)
{
sum+=a[i];
}
ans=min(ans,sum);
for(int i=0;i<n-k;i++)
{
if(k<n)
{
sum-=a[k-1];
sum+=a[k];
ans=min(sum,ans);
sum-=a[k];
sum+=a[k-1];
}
if(i>0)
{
sum-=a[i];
sum+=a[i-1];
ans=min(sum,ans);
sum-=a[i-1];
sum+=a[i];
}
sum-=a[i];
k++;
sum+=a[k+i];
ans=min(ans,sum);
}
cout<<ans<<endl;
}
return 0;
}