#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const long long inf = 1e18;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<pair<int, int>> arr(n);
    int nodd = 0, neven = 0;
    int a;
    for (int i = 0; i < n; i++) {
      cin >> a;
      arr[i] = {a, i};
      if (a % 2 == 1)
        nodd++;
      else
        neven++;
    }
    if (abs(neven - nodd) > 1)
      cout << -1 << endl;
    else {
      queue<pair<int, int>> evens, odds;
      for (int i = 0; i < n; i++) {
        if (arr[i].first % 2 == 0) {
          evens.push({arr[i].first, arr[i].second});
        } else
          odds.push({arr[i].first, arr[i].second});
      }
      vector<pair<int, int>> nw;
      pair<int, int> e;
      int ans = 0;
      if (neven > nodd) {
        for (int i = 0; i < n; i++) {
          if (i % 2 == 0) {
            e = evens.front();
            evens.pop();
          } else {
            e = odds.front();
            odds.pop();
          }
          nw.emplace_back(e);
        }
        for (int i = 0; i < nw.size(); i++) {
          if (nw[i].first % 2 == 1) {
            ans += abs(nw[i].second - i);
          }
        }
        cout << ans << endl;
      } else if (neven < nodd) {
        for (int i = 0; i < n; i++) {
          if (i % 2 == 1) {
            e = evens.front();
            evens.pop();
          } else {
            e = odds.front();
            odds.pop();
          }
          nw.emplace_back(e);
        }
        for (int i = 0; i < nw.size(); i++) {
          if (nw[i].first % 2 == 0) {
            ans += abs(nw[i].second - i);
          }
        }
        cout << ans << endl;
      } else {
        for (int i = 0; i < n; i++) {
          if (i % 2 == 1) {
            e = evens.front();
            evens.pop();
          } else {
            e = odds.front();
            odds.pop();
          }
          nw.emplace_back(e);
        }
        for (int i = 0; i < nw.size(); i++) {
          if (nw[i].first % 2 == 0) {
            ans += abs(nw[i].second - i);
          }
        }
        int anss = 0;
        nw.clear();
        for (int i = 0; i < n; i++) {
          if (arr[i].first % 2 == 0) {
            evens.push({arr[i].first, arr[i].second});
          } else
            odds.push({arr[i].first, arr[i].second});
        }
        for (int i = 0; i < n; i++) {
          if (i % 2 == 0) {
            e = evens.front();
            evens.pop();
          } else {
            e = odds.front();
            odds.pop();
          }
          nw.emplace_back(e);
        }
        for (int i = 0; i < nw.size(); i++) {
          if (nw[i].first % 2 == 1) {
            anss += abs(nw[i].second - i);
          }
        }
        cout << min(anss, ans) << endl;
      }
    }
  }
  return 0;
}
