#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 50;
int T;
int n, k, a[N];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n * k; i++) scanf("%d", &a[i]);
    sort(a + 1, a + n * k + 1);
    int mid = (n + 1) / 2;
    long long ans = 0;
    for (int i = (mid - 1) * k + 1; i <= n * k; i += n - mid + 1) ans += a[i];
    printf("%lld\n", ans);
  }
  return 0;
}
