// Arup Guha
// 6/16/2023
// CF Div 3 Round 878 Problem B
// https://codeforces.com/contest/1840/problem/B

using namespace std;
#include <bits/stdc++.h>
typedef long long ll;

int main() {

    int nC,tmp;
    cin >> nC;

    // Process cases.
    for (int loop=0; loop<nC; loop++) {

        // Get basic input.
        int n, k, maxTemp;
        cin >> n >> k >> maxTemp;

        ll res = 0;
        ll streak = 0;

        // Go through the data.
        for (int i=0; i<n; i++) {

            cin >> tmp;

            // Streak continues.
            if (tmp<=maxTemp) {
                streak++;
            }

            // End of streak, add all relevant contiguous subsequences...
            else {
                if (streak >= k)
                    res = res + ( (streak-k+1)*(streak-k+2)/2 );

                // This gets reset.
                streak = 0;
            }
        }

        // Process the last streak if necessary, then output result.
        if (streak>= k) res = res + ( (streak-k+1)*(streak-k+2)/2 );
        cout << res << endl;
    }

    return 0;
}
