#include #include #include #include #define LL long long using namespace std; inline LL read() { LL x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m,k,cnt,sum; queueq; LL ans; inline void work() { n=read();m=read();k=read();ans=0;cnt=0;sum=0; while (!q.empty())q.pop(); for (int i=1;i<=n;i++) { int x=read(); if (x>=m)x=1;else x=0; q.push(x);cnt++;if (x)sum++; if(x&&sum==k) { while (q.front()==0){cnt--;q.pop();} cnt--;q.pop();sum--; } ans+=i-cnt; } printf("%I64d\n",ans); } int main() { int T=read(); while (T--)work(); }