#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pi;
typedef pair<char, ll> pci;
typedef vector<pi> vii;
typedef map<ll, ll> mi;
typedef set<ll> seti;
#define sz size()
#define ins insert
#define mp make_pair
#define pb push_back
#define nl << "\n";
#define all(x) x.begin(), x.end()
#define db(x) cout << #x << " = " << x nl
#define input(x) for (auto &a : x) cin >> a;
#define view(x) cout << #x << ": "; for (auto a : x) {cout << a << " ";} cout nl
#define viewp(x) cout << #x << ": "; for (auto &a : x) {cout << a.first << " " << a.second nl}
void solve() {
ll n, k;
cin >> n >> k;
vi a(n);
input(a);
ll minsum = 1e10, mini = n;
for (ll i = 0; i <= n - k; i++) {
ll sum = 0;
for (ll j = i; j < i + k; j++) {
sum += a[j];
}
if (sum < minsum) {
minsum = sum;
mini = i;
}
}
vi newarr;
for (int i = mini; i < mini + k; i++) {
newarr.pb(a[i]);
}
ll newsum = accumulate(all(newarr), 0);
vi newarr2 = newarr;
vi c = a;
sort(all(c));
sort(all(newarr2));
ll newmax = newarr2[k - 1];
for (ll i = 0; i < n; i++) {
if (find(all(newarr), c[i]) == newarr.end()) {
ll newsum2 = newsum;
newsum2 -= newmax;
newsum2 += c[i];
if (newsum2 < newsum) {
newsum = newsum2;
}
break;
}
}
cout << newsum nl
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}