#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const long long MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int MAXN = 1000050;
long long a[MAXN];
void solve(int T) {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n * k; i++) {
    scanf("%lld", &a[i]);
  }
  int jd = n - (n + 1) / 2;
  sort(a + 1, a + n * k + 1);
  reverse(a + 1, a + n * k + 1);
  int now = 0;
  long long ans = 0;
  int cnt = 0;
  for (int i = 1; i <= n * k && cnt < k; i++) {
    if (now < jd) {
      now++;
      continue;
    }
    cnt++;
    now = 0;
    ans += a[i];
  }
  printf("%lld\n", ans);
}
signed main() {
  int t = 1;
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}
