#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
const int MOD = 1000000007;
using namespace std;
int main(int argc, char *argv[]) {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int ara[(n * k) + 10];
    for (int i = 1; i <= n * k; i++) cin >> ara[i];
    sort(ara + 1, ara + (n * k) + 1, greater<int>());
    int size = (n / 2) + 1;
    int v = k;
    long long sum = 0;
    for (int i = size; i <= n * k && v > 0; i += size) {
      sum += ara[i];
      v--;
    }
    cout << sum << '\n';
    cout << '\n';
  }
  return 0;
}
