#include <bits/stdc++.h>
using namespace std;
void debug(queue<int> q) {
  cout << "[] ";
  while (!q.empty()) {
    cout << q.front() << " ";
    q.pop();
  }
  cout << "\n";
}
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<pair<int, int> > odd;
  vector<pair<int, int> > even;
  for (int i = 0; i < n; i++) {
    if (v[i] & 1)
      odd.push_back(make_pair(v[i], i));
    else
      even.push_back(make_pair(v[i], i));
  }
  if (abs((int)odd.size() - (int)even.size()) <= 1) {
    int ans = -1;
    if (odd.size() >= even.size()) {
      int cur = 0;
      queue<int> ganjil;
      queue<int> genap;
      int idx = 0;
      bool isOdd = true;
      while (idx < n) {
        if (v[idx] & 1)
          ganjil.push(v[idx]);
        else
          genap.push(v[idx]);
        while (true) {
          if (isOdd) {
            if (!ganjil.empty()) {
              cur += genap.size();
              ganjil.pop();
              isOdd = !isOdd;
            } else
              break;
          } else {
            if (!genap.empty()) {
              cur += ganjil.size();
              genap.pop();
              isOdd = !isOdd;
            } else
              break;
          }
        }
        idx++;
      }
      if (ans == -1 || cur < ans) ans = cur;
    }
    if (odd.size() <= even.size()) {
      int cur = 0;
      queue<int> ganjil;
      queue<int> genap;
      int idx = 0;
      bool isOdd = false;
      while (idx < n) {
        if (v[idx] & 1)
          ganjil.push(v[idx]);
        else
          genap.push(v[idx]);
        while (true) {
          if (isOdd) {
            if (!ganjil.empty()) {
              cur += genap.size();
              ganjil.pop();
              isOdd = !isOdd;
            } else
              break;
          } else {
            if (!genap.empty()) {
              cur += ganjil.size();
              genap.pop();
              isOdd = !isOdd;
            } else
              break;
          }
        }
        idx++;
      }
      if (ans == -1 || cur < ans) ans = cur;
    }
    cout << ans << "\n";
  } else {
    cout << -1 << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  cin >> t;
  for (int tt = 0; tt < t; tt++) {
    solve();
  }
  return 0;
}
