#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> js;
    vector<int> os;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if (x & 1)
        js.push_back(i);
      else
        os.push_back(i);
    }
    if (abs((int)js.size() - (int)os.size()) >= 2)
      cout << -1 << endl;
    else {
      if (n & 1) {
        if ((int)js.size() > (int)os.size()) {
          int sum = 0;
          int sb = 1;
          for (int i = 0; i < js.size(); i++) {
            sum += abs(js[i] - sb);
            sb += 2;
          }
          cout << sum << endl;
        } else {
          int sum = 0;
          int sb = 1;
          for (int i = 0; i < os.size(); i++) {
            sum += abs(os[i] - sb);
            sb += 2;
          }
          cout << sum << endl;
        }
      } else {
        int sum1 = 0;
        int sb = 1;
        for (int i = 0; i < js.size(); i++) {
          sum1 += abs(js[i] - sb);
          sb += 2;
        }
        int sum2 = 0;
        sb = 2;
        for (int i = 0; i < js.size(); i++) {
          sum2 += abs(js[i] - sb);
          sb += 2;
        }
        cout << min(sum1, sum2) << endl;
      }
    }
  }
}
