#include <iostream>
#include <vector>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while(t--){
        int n;
        long long k, x;
        cin >> n >> k >> x;
        vector<long long> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
 
        // Compute prefix sums for one block.
        // A[0] = 0, A[i] = a[0] + a[1] + ... + a[i-1] for i>=1.
        vector<long long> A(n+1, 0);
        for (int i = 0; i < n; i++){
            A[i+1] = A[i] + a[i];
        }
        long long S = A[n];  // total sum of one copy of a
        long long total = k * S; // total sum of b
        
        // If the entire array b sums to less than x, then no segment can have sum >= x.
        if(total < x){
            cout << 0 << "\n";
            continue;
        }
        
        // For any starting position l (which corresponds to some block r and index i in [0, n-1]),
        // the prefix sum at that position is r*S + A[i] (with A[0]=0, A[i] for i>=1).
        // We need there to exist an r' (with r'>= current index's block)
        // such that the sum of the segment [l, r'] >= x.
        // Because all numbers are positive, the prefix sum is strictly increasing.
        // The condition is equivalent to:
        //   r*S + A[i] <= total - x.
        // Let tVal = total - x.
        // Then for a fixed remainder index i, we need:
        //   r <= (tVal - A[i]) / S,  with r in [0, k-1].
        
        long long tVal = total - x;
        long long ans = 0;
        for (int i = 0; i < n; i++){
            if(tVal < A[i]) continue;  // no valid block r exists for this remainder
            long long maxR = (tVal - A[i]) / S;
            if(maxR >= k) maxR = k - 1; // ensure r is within [0, k-1]
            ans += (maxR + 1);
        }
 
        cout << ans << "\n";
    }
    return 0;
}
