#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long ll;
// A value to represent an impossible (unreachable) state.
const ll NEG_INF = -1e18;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--){
int n, k;
cin >> n >> k;
vector<ll> d(n);
for (int i = 0; i < n; i++){
cin >> d[i];
}
// We'll use a 1D dp array for the current minute, indexed by "r" (pending sushi).
// The maximum r at minute i is at most (n - i) (since you cannot have more pending pieces than minutes remaining to eat them).
vector<ll> dp(n+1, NEG_INF), next_dp(n+1, NEG_INF);
dp[0] = 0;
for (int i = 0; i < n; i++){
// Clear next_dp.
fill(next_dp.begin(), next_dp.end(), NEG_INF);
int rem = n - i - 1; // minutes left after minute i
for (int r = 0; r <= rem + k; r++){
if(dp[r] == NEG_INF) continue;
ll cur = dp[r];
// Option 1: Do nothing.
if(r <= rem)
next_dp[r] = max(next_dp[r], cur);
// Option 2: Eat one piece (only if pending > 0).
if(r > 0 && (r - 1) <= rem)
next_dp[r - 1] = max(next_dp[r - 1], cur);
// Option 3: Take the plate delivered at minute i.
// Only possible if after adding k pieces, pending does not exceed the remaining minutes.
if(r + k <= rem)
next_dp[r + k] = max(next_dp[r + k], cur + d[i]);
}
dp.swap(next_dp);
}
cout << dp[0] << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bGltaXRzPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKIAovLyBBIHZhbHVlIHRvIHJlcHJlc2VudCBhbiBpbXBvc3NpYmxlICh1bnJlYWNoYWJsZSkgc3RhdGUuCmNvbnN0IGxsIE5FR19JTkYgPSAtMWUxODsKIAppbnQgbWFpbigpewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShudWxscHRyKTsKICAgIAogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlKHQtLSl7CiAgICAgICAgaW50IG4sIGs7CiAgICAgICAgY2luID4+IG4gPj4gazsKICAgICAgICB2ZWN0b3I8bGw+IGQobik7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgICAgICBjaW4gPj4gZFtpXTsKICAgICAgICB9CiAKICAgICAgICAvLyBXZSdsbCB1c2UgYSAxRCBkcCBhcnJheSBmb3IgdGhlIGN1cnJlbnQgbWludXRlLCBpbmRleGVkIGJ5ICJyIiAocGVuZGluZyBzdXNoaSkuCiAgICAgICAgLy8gVGhlIG1heGltdW0gciBhdCBtaW51dGUgaSBpcyBhdCBtb3N0IChuIC0gaSkgKHNpbmNlIHlvdSBjYW5ub3QgaGF2ZSBtb3JlIHBlbmRpbmcgcGllY2VzIHRoYW4gbWludXRlcyByZW1haW5pbmcgdG8gZWF0IHRoZW0pLgogICAgICAgIHZlY3RvcjxsbD4gZHAobisxLCBORUdfSU5GKSwgbmV4dF9kcChuKzEsIE5FR19JTkYpOwogICAgICAgIGRwWzBdID0gMDsKIAogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICAgICAgLy8gQ2xlYXIgbmV4dF9kcC4KICAgICAgICAgICAgZmlsbChuZXh0X2RwLmJlZ2luKCksIG5leHRfZHAuZW5kKCksIE5FR19JTkYpOwogICAgICAgICAgICBpbnQgcmVtID0gbiAtIGkgLSAxOyAvLyBtaW51dGVzIGxlZnQgYWZ0ZXIgbWludXRlIGkKICAgICAgICAgICAgZm9yIChpbnQgciA9IDA7IHIgPD0gcmVtICsgazsgcisrKXsKICAgICAgICAgICAgICAgIGlmKGRwW3JdID09IE5FR19JTkYpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgbGwgY3VyID0gZHBbcl07CiAgICAgICAgICAgICAgICAvLyBPcHRpb24gMTogRG8gbm90aGluZy4KICAgICAgICAgICAgICAgIGlmKHIgPD0gcmVtKQogICAgICAgICAgICAgICAgICAgIG5leHRfZHBbcl0gPSBtYXgobmV4dF9kcFtyXSwgY3VyKTsKIAogICAgICAgICAgICAgICAgLy8gT3B0aW9uIDI6IEVhdCBvbmUgcGllY2UgKG9ubHkgaWYgcGVuZGluZyA+IDApLgogICAgICAgICAgICAgICAgaWYociA+IDAgJiYgKHIgLSAxKSA8PSByZW0pCiAgICAgICAgICAgICAgICAgICAgbmV4dF9kcFtyIC0gMV0gPSBtYXgobmV4dF9kcFtyIC0gMV0sIGN1cik7CiAKICAgICAgICAgICAgICAgIC8vIE9wdGlvbiAzOiBUYWtlIHRoZSBwbGF0ZSBkZWxpdmVyZWQgYXQgbWludXRlIGkuCiAgICAgICAgICAgICAgICAvLyBPbmx5IHBvc3NpYmxlIGlmIGFmdGVyIGFkZGluZyBrIHBpZWNlcywgcGVuZGluZyBkb2VzIG5vdCBleGNlZWQgdGhlIHJlbWFpbmluZyBtaW51dGVzLgogICAgICAgICAgICAgICAgaWYociArIGsgPD0gcmVtKQogICAgICAgICAgICAgICAgICAgIG5leHRfZHBbciArIGtdID0gbWF4KG5leHRfZHBbciArIGtdLCBjdXIgKyBkW2ldKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkcC5zd2FwKG5leHRfZHApOwogICAgICAgIH0KIAogICAgICAgIGNvdXQgPDwgZHBbMF0gPDwgIlxuIjsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==