#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, ans = INT_MAX;
    cin >> n;
    vector<int> a(n);
    for (int &i : a) cin >> i, i %= 2;
    for (int f = 0; f < 2; f++) {
      vector<int> pos, x;
      for (int i = f; i < n; i += 2) pos.push_back(i);
      for (int i = 0; i < n; i++)
        if (a[i]) x.push_back(i);
      if (pos.size() == x.size()) {
        int cur_ans = 0;
        for (int i = 0; i < pos.size(); i++) cur_ans += abs(pos[i] - x[i]);
        ans = min(ans, cur_ans);
      }
    }
    if (ans == INT_MAX) ans = -1;
    cout << ans << '\n';
  }
}
