#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        vector<long long> a(n), pre(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        pre[0] = a[0]%k;
        for (int i = 1; i < n; i++) pre[i] = (pre[i - 1] + a[i])%k;

        vector<int> cnt(k);
        long long ans = 0;

        for (int i = k; i < n; i++) {
            int j = i - k - 1;
            if (j < 0) cnt[0]++;
            else cnt[pre[j]]++;
            ans += cnt[pre[i]];
        }

        cout << ans << '\n';
    }
}
