#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBtYWluKCl7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgCiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUodC0tKXsKICAgICAgICBpbnQgbjsKICAgICAgICBsb25nIGxvbmcgaywgeDsKICAgICAgICBjaW4gPj4gbiA+PiBrID4+IHg7CiAgICAgICAgdmVjdG9yPGxvbmcgbG9uZz4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CByJz49IGN1cnJlbnQgaW5kZXgncyBibG9jaykKICAgICAgICAvLyBzdWNoIHRoYXQgdGhlIHN1bSBvZiB0aGUgc2VnbWVudCBbbCwgciddID49IHguCiAgICAgICAgLy8gQmVjYXVzZSBhbGwgbnVtYmVycyBhcmUgcG9zaXRpdmUsIHRoZSBwcmVmaXggc3VtIGlzIHN0cmljdGx5IGluY3JlYXNpbmcuCiAgICAgICAgLy8gVGhlIGNvbmRpdGlvbiBpcyBlcXVpdmFsZW50IHRvOgogICAgICAgIC8vICAgcipTICsgQVtpXSA8PSB0b3RhbCAtIHguCiAgICAgICAgLy8gTGV0IHRWYWwgPSB0b3RhbCAtIHguCiAgICAgICAgLy8gVGhlbiBmb3IgYSBmaXhlZCByZW1haW5kZXIgaW5kZXggaSwgd2UgbmVlZDoKICAgICAgICAvLyAgIHIgPD0gKHRWYWwgLSBBW2ldKSAvIFMsICB3aXRoIHIgaW4gWzAsIGstMV0uCiAgICAgICAgCiAgICAgICAgbG9uZyBsb25nIHRWYWwgPSB0b3RhbCAtIHg7CiAgICAgICAgbG9uZyBsb25nIGFucyA9IDA7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgICAgICBpZih0VmFsIDwgQVtpXSkgY29udGludWU7ICAvLyBubyB2YWxpZCBibG9jayByIGV4aXN0cyBmb3IgdGhpcyByZW1haW5kZXIKICAgICAgICAgICAgbG9uZyBsb25nIG1heFIgPSAodFZhbCAtIEFbaV0pIC8gUzsKICAgICAgICAgICAgaWYobWF4UiA+PSBrKSBtYXhSID0gayAtIDE7IC8vIGVuc3VyZSByIGlzIHdpdGhpbiBbMCwgay0xXQogICAgICAgICAgICBhbnMgKz0gKG1heFIgKyAxKTsKICAgICAgICB9CiAKICAgICAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwogICAgfQogICAgcmV0dXJuIDA7Cn0K
Nwo1IDMgMTAKMyA0IDIgMSA1CjE1IDk3NjIzIDEzMDAxMTEKMTA1IDk1IDEwOCAxMTEgMTE4IDEwMSA5NSAxMTggOTcgMTA4IDExMSAxMTQgOTcgMTEwIDExNgoxIDEwMDAwMCAxMjM0NTY3ODkxMDExCjEKMSAxIDEKMQoxIDEgMQoyCjIgMSAyCjEgMQoyIDEgNQoyIDEK
7
5 3 10
3 4 2 1 5
15 97623 1300111
105 95 108 111 118 101 95 118 97 108 111 114 97 110 116
1 100000 1234567891011
1
1 1 1
1
1 1 1
2
2 1 2
1 1
2 1 5
2 1