#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::string;
using std::vector;
using ll = long long;
void f() {
  int n, k;
  cin >> n >> k;
  vector<int> in(n * k);
  for (auto& it : in) cin >> it;
  std::sort(in.begin(), in.end());
  ll ans = 0;
  for (int i = 0; i != k; ++i)
    ans += in[((n - 1) / 2 * k) + i * (n - (n - 1) / 2)];
  cout << ans << '\n';
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) f();
  return 0;
}
