#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> v;
vector<long long> res;
long long num[1000 * 1000];
void solve() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  for (int i = 0; i < n * k; i++) scanf("%lld", &num[i]);
  sort(num, num + n * k);
  long long sum = 0, idx = (long long)ceil(n / 2.0) - 1;
  for (int i = 0; i < k; i++) sum += num[k * idx + i * (n - idx)];
  printf("%lld\n", sum);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
