#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int N=2e5+5;
pii dp[N];
int n,k,s;
int a[N],pre[N];
int check(int pen){
    int l=0;
    for(int i=1; i<=n; i++){
        dp[i]=make_pair(dp[i-1].first+pen,dp[i-1].second+1);
        if(i>1) dp[i]=max(dp[i],dp[i-1]);
        while(l<i && pre[i]-pre[l+1]>=s) l++;
        if(pre[i]-pre[l]>=s){
            dp[i]=max(dp[i],make_pair(dp[l].first+1+pen,dp[l].second+1));
        }
    }
//    cerr<<pen<<' '<<dp[n].sl<<'\n';
    return dp[n].second;
}
void Solve(){
    cin>>n>>k>>s;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        pre[i]=pre[i-1]+a[i];
    }
    int l=-n,r=n,m,kq=-1e9;
    dp[0]={0,0};
    int sl=0;
    while(l<=r){
        m=(l+r)/2;
        if(check(m)>=k){
            r=m-1;
            kq=m;
        }
        else{
            l=m+1;
        }
    }
    check(kq);
    cout<<dp[n].first-k*kq<<'\n';
}
signed main(){
     freopen("SKS.inp","r",stdin);
     freopen("SKS.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int Cases=1;
     cin>>Cases;
    while(Cases--){
        Solve();
    }
}
