#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;
// Function to calculate the minimum sum of a subarray of length K
int findMinSumWithSwap(int N, int K, vector<int>& A) {
// Compute initial minimum sum using a sliding window
int currentSum = 0, minSum = INT_MAX;
for (int i = 0; i < K; ++i)
currentSum += A[i];
minSum = currentSum;
for (int i = K; i < N; ++i) {
currentSum += A[i] - A[i - K];
minSum = min(minSum, currentSum);
}
// Try swapping every pair of elements
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
// Swap elements A[i] and A[j]
swap(A[i], A[j]);
// Recompute the sliding window minimum sum
currentSum = 0;
for (int k = 0; k < K; ++k)
currentSum += A[k];
int swappedMinSum = currentSum;
for (int k = K; k < N; ++k) {
currentSum += A[k] - A[k - K];
swappedMinSum = min(swappedMinSum, currentSum);
}
// Update the overall minimum sum
minSum = min(minSum, swappedMinSum);
// Swap back to restore the original array
swap(A[i], A[j]);
}
}
return minSum;
}
int main() {
int T;
cin >> T;
while (T--) {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
cout << findMinSumWithSwap(N, K, A) << endl;
}
return 0;
}