#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (long long int loop = 0; loop < t; loop++) {
    int n, k;
    cin >> n >> k;
    int a[n * k];
    for (long long int i = 0; i < n * k; i++) cin >> a[i];
    int b[k][n];
    int y = 0;
    for (int i = 0; i < k; i++)
      for (int j = 0; j < (n - 1) / 2; j++, y++) {
        b[i][j] = a[y];
      }
    int p = k - 1;
    int j = (n - 1) / 2;
    for (int i = k * ((n - 1) / 2); i < n * k; i++, j++) {
      if (j == n) {
        j = (n - 1) / 2;
        p--;
      }
      b[p][j] = a[i];
    }
    int pos = n / 2;
    if (n % 2 != 0) pos++;
    pos--;
    long long sum = 0;
    if (n != 2) {
      for (int i = 0; i < k; i++) sum += b[i][pos];
      cout << sum << '\n';
    } else {
      for (int i = 0; i < n * k; i += 2) sum += a[i];
      cout << sum << '\n';
    }
  }
  return 0;
}
