#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 50;
long long a[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n * k; i++) {
      cin >> a[i];
    }
    sort(a, a + n * k);
    int num = (n - 1) / 2;
    long long ans = 0;
    int cnt = 0;
    for (int i = k * num; i < n * k; i += (n - num)) {
      ans += a[i];
    }
    cout << ans << endl;
  }
  return 0;
}
