#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long odd = 0;
    for (long long i = 0; i < n; i++) odd += (a[i] % 2);
    long long even = n - odd;
    if (odd > (n + 1) / 2 || even > (n + 1) / 2)
      cout << -1 << '\n';
    else {
      if (n % 2 == 0) {
        long long epos = 0, opos = 1, ans1 = 0, ans2 = 0;
        for (long long i = 0; i < n; i++) {
          if (a[i] % 2 == 1) {
            ans1 += abs(epos - i);
            ans2 += abs(opos - i);
            epos += 2;
            opos += 2;
          }
        }
        cout << min(ans1, ans2) << '\n';
      } else {
        long long pos = 0, ans = 0;
        if (odd == (n + 1) / 2) {
          for (long long i = 0; i < n; i++) {
            if (a[i] % 2 == 1) {
              ans += abs(pos - i);
              pos += 2;
            }
          }
        } else {
          for (long long i = 0; i < n; i++) {
            if (a[i] % 2 == 0) {
              ans += abs(pos - i);
              pos += 2;
            }
          }
        }
        cout << ans << '\n';
      }
    }
  }
  return 0;
}
