#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){
for(int i = 1; i <= n; i++) if(k * pre[n] - (x * pre[n] + pre[i]) >= lim){
ans = x * n + i + 1;
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))R = mid - 1;
else L = mid + 1;
}
cout << ans<< endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwpjb25zdCBpbnQgTUFYTiA9IDFlNSArIDc7CmxsIGFbTUFYTl0sIHByZVtNQVhOXSwgbiwgaywgbGltLCB0LCBhbnM7Cgpib29sIGNoZWNrKGxsIHgpewogICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspIGlmKGsgKiBwcmVbbl0gLSAoeCAqIHByZVtuXSArIHByZVtpXSkgPj0gbGltKXsKICAgICAgICBhbnMgPSB4ICogbiArIGkgKyAxOwogICAgICAgIHJldHVybiAxOwogICAgfQogICAgcmV0dXJuIDA7Cn0KCgppbnQgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNvdXQudGllKDApOwogICAgY2luLnRpZSgwKTsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUodC0tKXsKICAgICAgICBjaW4gPj4gbiA+PiBrID4+IGxpbTsKICAgICAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CiAgICAgICAgICAgIGNpbiA+PiBhW2ldOwogICAgICAgICAgICBwcmVbaV0gPSBwcmVbaSAtIDFdICsgYVtpXTsKICAgICAgICB9CiAgICAgICAgbGwgTCA9IDAsIFIgPSBrIC0gMTsKICAgICAgICBhbnMgPSAwOwogICAgICAgIHdoaWxlKEwgPD0gUil7CiAgICAgICAgICAgIGludCBtaWQgPSAoTCArIFIpIC8gMjsKICAgICAgICAgICAgaWYoY2hlY2sobWlkKSlSID0gbWlkIC0gMTsKICAgICAgICAgICAgZWxzZSBMID0gbWlkICsgMTsKICAgICAgICB9CiAgICAgICAgY291dCA8PCBhbnM8PCBlbmRsOwogICAgfQp9