#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007;
const long long INF = 999999999999999999;
const long long NN = (long long)(1e6 + 5);
long long min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
long long max(long long x, long long y) {
  if (x > y) return x;
  return y;
}
long long power(long long x, unsigned long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long hcf(long long a, long long b) {
  if (b == 0) return a;
  return hcf(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long TT = 1;
  cin >> TT;
  while (TT--) {
    long long n, k, i;
    cin >> n >> k;
    vector<long long> v(n * k);
    for (auto &u : v) cin >> u;
    v.push_back(-INF);
    sort(v.begin(), v.end());
    long long ans = 0;
    vector<long long> V[k];
    long long x = (n + 1) / 2, l = 1, r = n * k;
    x--;
    for (i = 0; i < k; i++) {
      long long c = 0;
      while (c < x) V[i].push_back(v[l++]), c++;
      c = 0;
      while (c < n - x) V[i].push_back(v[r--]), c++;
    }
    for (i = 0; i < k; i++) {
      sort(V[i].begin(), V[i].end());
      ans += V[i][x];
    }
    cout << ans << "\n";
  }
}
