/* ********************************* Author :clogos Created Time :2016/08/06 19:26:44 File Name :C.cpp ********************************** */ #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int inf = 0x3f3f3f3f; const int N = 200000 + 10; int a[N]; int dp[N]; int main() { //freopen("out", "w", stdout); //freopen("in", "r", stdin); int cases; scanf("%d", &cases); while(cases--) { int n, m, k; scanf("%d%d%d", &n, &m, &k); for(int i = 0; i < n; ++i) scanf("%d", &a[i]); int tol = 0; for(int i = 0; i < n; ++i) { if(a[i] >= m) tol++; dp[i] = tol; } long long ans = 0; int ln = -1; for(int i = n-1; i >= 0; --i) if(dp[i] >= k) { ln = i; break; } int tk = k, lp = k-1; for(int i = 0; i + tk <= n; ++i) { while(lp < n && dp[lp] < k) lp++; lp = max(lp, i+tk-1); ans += max(0, ln - lp + 1); if(a[i] >= m) k++; //cout << i << " " << ans << endl; } cout << ans << endl; } return 0; }