#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2) #define MEM(a,b) memset(a,b,sizeof(a)) #define MP(a,b) make_pair(a,b) #define PB push_back typedef long long ll; typedef pair pii; const double eps = 1e-8; const int INF = (1 << 30) - 1; const int maxn = 200010; int T,n,m,k,A[maxn]; int C[maxn]; void Add(int x,int d){ while(x <= n){ C[x] += d; x += x & (-x); } } int Get(int x){ int res = 0; while(x){ res += C[x]; x -= x & (-x); } return res; } int main(){ scanf("%d",&T); while(T--){ scanf("%d%d%d",&n,&m,&k); memset(C,0,sizeof(C)); for(int i = 1; i <= n; ++i){ scanf("%d",&A[i]); if(A[i] >= m) Add(i,1); } ll ans = 0; for(int i = 1; i <= n; ++i){ if(i + k - 1 > n) break; int l = i + k - 1,r = n,pre = Get(i - 1); while(l < r){ int mid = getmid(l,r); int res = Get(mid) - pre; if(res < k) l = mid + 1; else r = mid; } int res = Get(l) - pre; if(res < k) l++; if(l <= n) ans += n - l + 1; //printf("%d : %d %d\n",i,l,n - l + 1); } printf("%I64d\n",ans); } return 0; }