#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int m = n * k;
    int a[m];
    for (int i = 0; i < m; i++) cin >> a[i];
    sort(a, a + k);
    int sum = 0;
    long long ans = 0;
    for (int i = m - n / 2 - 1; sum < k; i -= (n + 2) / 2) {
      ans += a[i];
      sum++;
    }
    cout << ans << endl;
  }
}
