#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define oset tree < pair<int, int> ,  null_type ,  less<pair<int, int>> ,  rb_tree_tag ,  tree_order_statistics_node_update >
using namespace std;
const int N = 1e5;
signed main(){
    //You are given an array A of length N (N<=2000)
    //You have to consider all contigious subarrays (O(N^2) is possible)
    //K is given as input
    //M x length of array >= k
    //M = ceil(k/length of array)
    //X = kth smallest element of B
    //The kth smallest element of B would be the ceil(K/M)th smallest element of S?
    //S = (1, 2, 3, 4, 5), M = 2  = (1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
    //B = (1, 1, 2, 2, 3, 3, 4, 4, 5, 5), find the 9th smallest element in B
    //The kth smallest element in B, would be the Yth smallest element in S
    //What is Y? Y = ceil(K/M)
    //ceil(9/2) = 5
    //5th smallest element of S, is 5 again
    //F is the frequency of X in S (the original subarray, before concatenation)
    //The subarray S is beautiful if F also occurs in S
    //We need to output the number of beautiful subarrays
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n, k;
        cin>>n>>k;
        int ans = 0;
        int a[n];
        for(int i = 0;i<n;i++) cin>>a[i];
        for(int i = 0;i<n;i++){
            int freq[2001];
            for(int i = 0;i<=2000;i++) freq[i] = 0;
            oset s;
            for(int j = i;j<n;j++){ //iterating over all subarrays i, i+1, i+2, .., j
                int m = ceil(((double)k)/(j - i + 1));
                int k1 = ceil(((double)k)/m);
                k1--; //we use 0 based indexing
                s.insert({a[j], freq[a[j]]++});
                auto it = s.find_by_order(k1);
                int element = (*it).first;
                int frequency = freq[element];
                if(freq[frequency]>0) ans++; //subarray is beautiful
                //We have a subarray i.. j
                //How do we find the kth smallest number in O(1) or O(LogN)?
            }
        }
        cout<<ans<<"\n";
    }
}
//acdabcd