#pragma comment(linker, "/STACK:102400000,102400000") #include #include #include #include #include #include #include #include #include #include using namespace std; const double eps = 1e-6; const double pi = acos(-1.0); const int INF = 1e9; const int MOD = 1e9+7; #define ll long long #define CL(a,b) memset(a,b,sizeof(a)) #define lson (i<<1) #define rson ((i<<1)|1) #define N 2000010 int gcd(int a,int b){return b?gcd(b,a%b):a;} int n,m,k; ll a[N],vis[N]; int main() { int t; scanf("%d",&t); while(t--) { int n,m,k; scanf("%d%d%d",&n,&m,&k); int num=0,len=0; ll ans=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(num=m) { vis[num++]=i; } if(num==k) { ans+=(n-i+1)*(vis[0]); } } else if(a[i]>=m) { vis[num++]=i; len=num-k; ll l=vis[len]-vis[len-1]; ll r=n-i+1; ans+=l*r; } } printf("%lld\n",ans); } return 0; }