#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = 1e9 + 7;
void solve(){
int n, k, m;
cin >> n >> m >> k;
vector<int> a(n);
int len = 0;
ll sum = 0;
ll ans = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
sum += a[i];
len++;
if(sum <= 0){
len = 0;
sum = 0;
}
ans = max(ans, (ll)(sum - (k * ceil(len * 1.0 / m))));
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for(int i = 1; i <= t; i++){
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1PRCA9IDFlOSArIDc7Cgp2b2lkIHNvbHZlKCl7CglpbnQgbiwgaywgbTsKCWNpbiA+PiBuID4+IG0gPj4gazsKCQoJdmVjdG9yPGludD4gYShuKTsKCQoJaW50IGxlbiA9IDA7CglsbCBzdW0gPSAwOwoJbGwgYW5zID0gMDsKCWZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewoJCWNpbiA+PiBhW2ldOwoJCXN1bSArPSBhW2ldOwoJCWxlbisrOwoJCWlmKHN1bSA8PSAwKXsKCQkJbGVuID0gMDsKCQkJc3VtID0gMDsKCQl9CgkJCgkJYW5zID0gbWF4KGFucywgKGxsKShzdW0gLSAoayAqIGNlaWwobGVuICogMS4wIC8gbSkpKSk7Cgl9Cgljb3V0IDw8IGFucyA8PCAiXG4iOwoJCn0KCmludCBtYWluKCl7Cglpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKCWNpbi50aWUobnVsbHB0cik7CgkKCWludCB0ID0gMTsKCWNpbiA+PiB0OwoJCglmb3IoaW50IGkgPSAxOyBpIDw9IHQ7IGkrKyl7CgkJc29sdmUoKTsKCX0KCXJldHVybiAwOwp9