#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n * k; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n * k);
    long long sum = 0;
    int tmp = n * k - n + (n + 1) / 2;
    int p = n - (n + 1) / 2 + 1;
    for (int i = 1; i <= k; i++) {
      sum += a[tmp];
      tmp -= p;
    }
    printf("%lld\n", sum);
  }
  return 0;
}
