description: <image>
  
  William has an array of n integers a_1, a_2, ..., a_n. In one move he can swap two neighboring items. Two items a_i and a_j are considered neighboring if the condition |i - j| = 1 is satisfied.
  
  William wants you to calculate the minimal number of swaps he would need to perform to make it so that the array does not contain two neighboring items with the same parity.
  
  Input
  
  Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). Description of the test cases follows.
  
  The first line of each test case contains an integer n (1 ≤ n ≤ 10^5) which is the total number of items in William's array.
  
  The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) which are William's array.
  
  It is guaranteed that the sum of n over all test cases does not exceed 10^5.
  
  Output
  
  For each test case output the minimal number of operations needed or -1 if it is impossible to get the array to a state when no neighboring numbers have the same parity.
  
  Example
  
  Input
  
  
  5
  3
  6 6 1
  1
  9
  6
  1 1 1 2 2 2
  2
  8 6
  6
  6 2 3 4 5 1
  
  
  Output
  
  
  1
  0
  3
  -1
  2
  
  Note
  
  In the first test case the following sequence of operations would satisfy the requirements: 
  
    1. swap(2, 3). Array after performing the operation: [6, 1, 6] 
  
  
  
  In the second test case the array initially does not contain two neighboring items of the same parity.
  
  In the third test case the following sequence of operations would satisfy the requirements: 
  
    1. swap(3, 4). Array after performing the operation: [1, 1, 2, 1, 2, 2] 
    2. swap(2, 3). Array after performing the operation: [1, 2, 1, 1, 2, 2] 
    3. swap(4, 5). Array after performing the operation: [1, 2, 1, 2, 1, 2] 
  
  
  
  In the fourth test case it is impossible to satisfy the requirements.
  
  In the fifth test case the following sequence of operations would satisfy the requirements: 
  
    1. swap(2, 3). Array after performing the operation: [6, 3, 2, 4, 5, 1] 
    2. swap(4, 5). Array after performing the operation: [6, 3, 2, 5, 4, 1] 
solution: import java.io.*;
  import java.util.Arrays;
  import java.util.*;
  import java.util.Scanner;
  import java.util.StringTokenizer;
  
  
  
  public class eashan{
  
  
      public static boolean checker(long[] arr,long K,long diff)
      {
          long collect=0;
          for(int i=0;i<arr.length;i++)
          {
              if(arr[i]>diff)
                  collect+=arr[i]-diff;
          }
  
          if(collect>=K)
              return true;
          else
              return false;
      }
      public static long search(long[] arr,long K,long R)
      {
          long l=0;
          long r=R;
  
          while(l<=r)
          {
              long mid=(l+r)/2;
  
              if(checker(arr,K,mid))
              {
                  if(checker(arr,K,mid+1))
                      l=mid+1;
                  else
                      return mid;
              }
              else
                  r=mid-1;
          }
          return -1;
      }
  
      static void sieveOfEratosthenes(int n,ArrayList<Integer> arr,ArrayList<Integer> arr1)
      {
          // Create a boolean array
          // "prime[0..n]" and
          // initialize all entries
          // it as true. A value in
          // prime[i] will finally be
          // false if i is Not a
          // prime, else true.
          boolean prime[] = new boolean[n + 1];
          for (int i = 0; i <= n; i++)
              prime[i] = true;
  
          for (int p = 2; p * p <= n; p++)
          {
              // If prime[p] is not changed, then it is a
              // prime
              if (prime[p] == true)
              {
  
                  // Update all multiples of p
                  for (int i = p * p; i <= n; i += p)
                      prime[i] = false;
              }
          }
  
          // Print all prime numbers
          int x=0;
          for (int i = 2; i <= n; i++)
          {
              if (prime[i] == true)
              {
  
                      arr.add(i);
  
  
              }
  
          }
          System.out.println(arr.size());
      }
  
      public static boolean check(long[] time,long complete,long tasks)
      {
          long c=0;
          for(int i=0;i<time.length;i++)
              c+=complete/time[i];
          if(c>=tasks)
              return true;
          else
              return false;
  
      }
  
      public static long sear(long[] arr,long tasks)
      {
          long l=0;
          long r=(long)Math.pow(10,18);
          while(l<=r)
          {
  
              long mid=(l+r)/2;
              //System.out.println(mid);
              //System.out.println(pro.get(mid));
              if(check(arr,mid,tasks))
              {
                  if(check(arr,mid-1,tasks))
                      r=mid-1;
                  else
                      return mid;
              }
  
              else
                  l=mid+1;
          }
          return -1;
      }
  
      public static long get_answer(int node_start, int node_end, int node_index, int query_start, int query_end, long seg_tree[])
      {
          if(query_start <= node_start && query_end >= node_end)
          {
              return seg_tree[node_index];
          }
  
          if(node_end < query_start || query_end < node_start)
          {
  //            long s=0;
              return (long)Math.pow(2,31)-1;
          }
  
          int mid=node_start+(node_end-node_start)/2;
          return get_answer(node_start, mid, 2*node_index+1, query_start, query_end, seg_tree)&
                  get_answer(mid+1, node_end, 2*node_index+2,query_start, query_end, seg_tree);
      }
  
      public static void update_recurse(long seg_tree[], int node_start, int node_end, int update_index, long old_value, long new_value, int node_index)
      {
          if(update_index < node_start || update_index > node_end)
              return;
  
          seg_tree[node_index] = (seg_tree[node_index]|old_value)&new_value;
          if(node_start!=node_end)
          {
              int mid = node_start+(node_end-node_start)/2;
              update_recurse(seg_tree, node_start,mid,update_index,old_value,new_value,2*node_index+1);
              update_recurse(seg_tree,mid+1,node_end,update_index,old_value, new_value, 2*node_index+2);
          }
      }
  
      public static void update(long elements[], long seg_tree[], int i, int N, long new_value)
      {
          if(i > 0 && i <= N-1)
          {
              int number_of_bits = (int)(Math.floor(Math.log(elements[i]) / Math.log(2))) + 1;
              long complement = elements[i]^(long)(Math.pow(2,31)-1);
  //            long complement = ~elements[i];
  //            System.out.println(complement);
  //            System.out.println((long)((1 << number_of_bits)-1));
  
              elements[i] = new_value;
  
              update_recurse(seg_tree,0,N-1,i,complement,new_value,0);
  
          }
  
      }
  
  
      public static long create_seg_tree(long elements[], int node_start, int node_end, long seg_tree[], int node_index)
      {
          if(node_start == node_end)
          {
              seg_tree[node_index]=elements[node_start];
              return elements[node_start];
          }
  
          int mid = node_start+(node_end-node_start)/2;
          seg_tree[node_index]=create_seg_tree(elements, node_start, mid, seg_tree, 2*node_index+1) & create_seg_tree(elements, mid+1, node_end, seg_tree, 2*node_index+2);
          return seg_tree[node_index];
      }
  
      public static void main(String[] args)throws IOException {
          Reader.init(System.in);
          BufferedWriter output=new BufferedWriter(new OutputStreamWriter(System.out));
          int T=Reader.nextInt();
          for(int m=1;m<=T;m++)
          {
              int N=Reader.nextInt();
              ArrayList<Integer> arr_even=new ArrayList<>();
              ArrayList<Integer> arr_odd=new ArrayList<>();
  
              for(int i=0;i<N;i++)
              {
                  int ch=Reader.nextInt();
  
                  if(ch%2==0)
                      arr_even.add(i);
                  else
                      arr_odd.add(i);
  
              }
  
              if(Math.abs(arr_even.size()-arr_odd.size())>1)
                  output.write(-1+"\n");
              else
              {
  
                      int ans1=0,ans2=0;
                      int pos=0,l=0;
                      while(l<arr_even.size())
                      {
                          ans1+=Math.abs(arr_even.get(l)-pos);
                          ++l;
                          pos+=2;
                      }
                      pos=0;l=0;
                  while(l<arr_odd.size())
                  {
                      ans2+=Math.abs(arr_odd.get(l)-pos);
                      ++l;
                      pos+=2;
                  }
                  if(arr_even.size()>arr_odd.size())
                      output.write(ans1+"\n");
                  else if(arr_even.size()<arr_odd.size())
                      output.write(ans2+"\n");
                      else
                  output.write(Math.min(ans1,ans2)+"\n");
  
  
              }
  
          }
  
          output.flush();
  
  
      }
  
  
  
  
  }
  
  class Reader {
      static BufferedReader reader;
      static StringTokenizer tokenizer;
  
      static void init(InputStream input) {
          reader = new BufferedReader(
                  new InputStreamReader(input));
          tokenizer = new StringTokenizer("");
      }
  
      static String next() throws IOException {
          while (!tokenizer.hasMoreTokens()) {
              tokenizer = new StringTokenizer(
                      reader.readLine());
          }
          return tokenizer.nextToken();
      }
  
      static int nextInt() throws IOException {
          return Integer.parseInt(next());
      }
  
      static long nextLong() throws IOException {
          return Long.parseLong(next());
      }
  
      static double nextDouble() throws IOException {
          return Double.parseDouble(next());
      }
  }
  
  
  