#include <bits/stdc++.h>
using namespace std;
string s;
long long k, n;
void solve() {
  cin >> n >> k;
  long long tot = n * k;
  long long a[tot], ans = 0;
  for (long long i = 0; i < tot; i++) cin >> a[i];
  sort(a, a + tot);
  long long skip = k * ((n - 1) / 2);
  long long i = skip;
  while (i < tot) {
    ans += a[i];
    long long cnt = (n / 2) + 1;
    while (cnt--) i++;
  }
  cout << ans << endl;
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
