#include <bits/stdc++.h>
long long mod = 1000000007;
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long check(string& s, string& t) {
  long long cnt = 0, n = s.size();
  vector<long long> a, b;
  for (int i = 0; i < n; i++) {
    if (t[i] != s[i]) {
      if (s[i] & 1) {
        a.push_back(i);
      } else {
        b.push_back(i);
      }
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  long long p = a.size(), q = b.size();
  for (int i = 0; i < min(p, q); i++) {
    cnt += abs(a[i] - b[i]);
  }
  return cnt;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long cnto = 0, cnte = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] & 1)
      cnto++;
    else
      cnte++;
  }
  if (n == 1) {
    cout << 0 << endl;
    return;
  }
  long long d = abs(cnto - cnte);
  if (d > 1) {
    cout << -1 << endl;
    return;
  }
  string s = "";
  for (auto x : a) {
    if (x & 1)
      s += '1';
    else
      s += '0';
  }
  string t = "";
  int f = 1;
  long long ans = 1e10;
  if (cnto > cnte) {
    for (int i = 0; i < n; i++) {
      if (f)
        t += '1', f = 0;
      else
        t += '0', f = 1;
    }
    ans = min(ans, check(s, t));
  } else if (cnte > cnto) {
    f = 1;
    t = "";
    for (int i = 0; i < n; i++) {
      if (f)
        t += '0', f = 0;
      else
        t += '1', f = 1;
    }
    ans = min(ans, check(s, t));
  } else {
    f = 1;
    t = "";
    for (int i = 0; i < n; i++) {
      if (f)
        t += '1', f = 0;
      else
        t += '0', f = 1;
    }
    ans = min(ans, check(s, t));
    reverse(t.begin(), t.end());
    ans = min(ans, check(s, t));
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
