#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
bool typetest;
inline void fastIOfileinput() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  typetest = 1;
}
const int N = 2e5 + 2;
int n, k;
ll a[N];
void Read() {
  cin >> n >> k;
  for (int i = 1; i <= n * k; ++i) cin >> a[i];
  sort(a + 1, a + n * k + 1);
}
void Solve() {
  int v = (n + 1) / 2;
  ll ans = 0, cnt(0);
  for (int i = n * k - (n - v + 1) + 1, j = 1; j <= k; ++j, i -= n - v + 1)
    ans += a[i];
  cout << ans << "\n";
}
int32_t main() {
  fastIOfileinput();
  if (typetest) {
    int t;
    cin >> t;
    for (int v = 1; v <= t; ++v) {
      Read();
      Solve();
    }
  } else {
    Read();
    Solve();
  }
}
