#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 5;
long long a[MAXN];
long long b[MAXN];
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long pos = 0;
    long long kk1 = 1;
    long long kk2 = 2;
    long long ans = 0;
    long long num1 = 0;
    long long num2 = 0;
    long long ans1 = 0;
    long long ans2 = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i], num1 += a[i] & 1, num2 += 1 - a[i] & 1;
      if (a[i] & 1) {
        ans1 += abs(kk1 - i), kk1 += 2;
        ans2 += abs(kk2 - i), kk2 += 2;
      }
    }
    if (abs(num1 - num2) > 1) {
      cout << -1 << endl;
      continue;
    }
    if (n % 2 == 1) {
      if (num1 > num2) {
        cout << ans1 << endl;
      } else
        cout << ans2 << endl;
      continue;
    }
    cout << min(ans1, ans2) << endl;
  }
}
