#include<bits/stdc++.h>
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define setbit0(n, i) ((n) & (~(1LL << (i))))
#define setbit1(n, i) ((n) | (1LL << (i)))
#define ll long long
#define int long long
template<typename s, typename t> void smax(s &a, const t &b) {if (a<b) a=b;}
template<typename s, typename t> void smin(s &a, const t &b) {if (a>b) a=b;}
char gap = 32;
#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define fill(x, y) memset(x, y, sizeof(x))
#define srt(v) sort(v.begin(), v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define lll __int128_t
ll hashPrime = 1610612741;
void solve() {
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
unordered_map<int, int> mp;
int sum = 0;
for (int i = 0; i < k; i++) {
sum += v[i];
}
mp[sum]++;
for (int i = k; i < n; i++) {
sum += v[i] - v[i - k];
mp[sum]++;
}
int freq = 0;
int mxF = 0;
for (auto& e : mp) {
if (e.second > mxF) {
mxF = e.second;
freq = e.first;
}
}
int cnt = 0;
sum = 0;
for (int i = 0; i < k; i++) {
sum += v[i];
}
if (sum != freq) cnt++;
for (int i = k; i < n; i++) {
sum += v[i] - v[i - k];
if (sum != freq) cnt++;
}
cout << cnt << endl;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t; cin >> t;
while(t--){
solve();
}
}