#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pb push_back
#define ll long long int
#define watch(x) cout<<(#x)<< "is" <<(x) <<endl
#define endl "\n"
#define vii vector<pair<int,int>>
#define f first
#define s second
template<typename T>
void output_vector(const vector<T> &v, bool add_one = false, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = int(v.size());
for (int i = start; i < end; i++)
cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
bool isPrime(ll n) {
if(n==2) return true;
for ( ll i = 2; i * i <= n; ++ i) {
if (n % i == 0) {
return false;
}
}
return true;
}
// bool prime[ll n];
// void SieveOfEratosthenes(ll n)
// {
// memset(prime, true, sizeof(prime));
// for (ll p = 2; p * p <= n; p++)
// {
// if (prime[p] == true)
// {
// for (ll i = p * p; i <= n; i += p)
// prime[i] = false;
// }
// }
// }
void solve()
{
int n;
cin>>n;
vi v(n);
int even = 0;
int odd = 0;
rep(i,0,n){
cin>>v[i];
if(v[i]&1){
odd++;
v[i]=1;
}
else{
even++;
v[i]=0;
}
}
// rep(i,0,n){
// cout<<v[i];
// }
if(n%2==0 && (even!=odd)){
// cout<<even<<" "<<odd<<endl;
cout<<-1<<endl;
return;
}
if((n&1) and abs(even-odd)!=1){
cout<<-1<<endl;
return;
}
int ans = 0;
for(int i = n-2; i>=0; i--){
if(v[i]!=v[i+1]) continue;
int j = i-1;
while(j>=0){
if(v[j]!=v[i]) break;
else j--;
}
swap(v[i],v[j]);
ans = ans + i - j;
}
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t; cin>>t;
while(t--){
solve();
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}