#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 7;
ll a[MAXN], pre[MAXN], n, k, lim, t, ans;
bool check(ll x){
bool kt = false;
for(int i = 0; i <= n; i++) if(k * pre[n] - (x * pre[n] + pre[i]) >= lim){
ans = x * n + i + 1;
kt = 1;
}
if(kt) return 1;
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> t;
while(t--){
cin >> n >> k >> lim;
for(int i = 1; i <= n; i++){
cin >> a[i];
pre[i] = pre[i - 1] + a[i];
}
ll L = 0, R = k - 1;
ans = 0;
while(L <= R){
int mid = (L + R) / 2;
if(check(mid))L = mid + 1;
else R = mid - 1;
}
cout << ans << endl;
for(int i = 1; i <= n; i++) pre[i] = a[i] = 0;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwpjb25zdCBpbnQgTUFYTiA9IDFlNSArIDc7CmxsIGFbTUFYTl0sIHByZVtNQVhOXSwgbiwgaywgbGltLCB0LCBhbnM7Cgpib29sIGNoZWNrKGxsIHgpewogICAgYm9vbCBrdCA9IGZhbHNlOwogICAgZm9yKGludCBpID0gMDsgaSA8PSBuOyBpKyspIGlmKGsgKiBwcmVbbl0gLSAoeCAqIHByZVtuXSArIHByZVtpXSkgPj0gbGltKXsKICAgICAgICBhbnMgPSB4ICogbiArIGkgKyAxOwogICAgICAgIGt0ID0gMTsKICAgIH0KICAgIGlmKGt0KSByZXR1cm4gMTsKICAgIHJldHVybiAwOwp9CgoKaW50IG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjb3V0LnRpZSgwKTsKICAgIGNpbi50aWUoMCk7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlKHQtLSl7CiAgICAgICAgY2luID4+IG4gPj4gayA+PiBsaW07CiAgICAgICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspewogICAgICAgICAgICBjaW4gPj4gYVtpXTsKICAgICAgICAgICAgcHJlW2ldID0gcHJlW2kgLSAxXSArIGFbaV07CiAgICAgICAgfQogICAgICAgIGxsIEwgPSAwLCBSID0gayAtIDE7CiAgICAgICAgYW5zID0gMDsKICAgICAgICB3aGlsZShMIDw9IFIpewogICAgICAgICAgICBpbnQgbWlkID0gKEwgKyBSKSAvIDI7CiAgICAgICAgICAgIGlmKGNoZWNrKG1pZCkpTCA9IG1pZCArIDE7CiAgICAgICAgICAgIGVsc2UgUiA9IG1pZCAtIDE7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgYW5zIDw8IGVuZGw7CiAgICAgICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHByZVtpXSA9IGFbaV0gPSAwOwogICAgfQp9