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: 
  //package com.company;
  
  
  
  import  java.math.*;
  import java.util.*;
  import java.lang.*;
  import java.io.*;
  
  
  
  public final class Main {
  
      FastReader s;
  
  
      public static void main (String[] args) throws java.lang.Exception
      {
  
          new Main().run();
  
      }
      void run()
      {
          s = new FastReader();
          solve();
      }
      StringBuffer sb;
  
      void solve()
      {
  
          sb = new StringBuffer();
  
  
  
          for(int T = s.nextInt();T > 0;T--)
          {
  
              start();
  
          }
  
           System.out.print(sb);
  
      }
  
  
      void start()
      {
         int n = s.nextInt();
         int arr[] = intArr(n);
         int odd = 0;
         int even = 0;
         for(int i : arr)
         {
             if(i%2 == 0)even++;
             else
                 odd++;
         }
         int l = n/2 + n%2;
         /// System.out.println(odd +" "+even+" "+l);
         if(Math.max(odd,even) > l)
         {
             //System.out.println("idhr hua " + n+" ka");
             sb.append("-1\n");
             return;
         }
         if(n%2 == 0)
         {
             ArrayList<Integer> x1 = new ArrayList<>();
             ArrayList<Integer> x2 = new ArrayList<>();//even pos pe even wale ko
             ArrayList<Integer> y1 = new ArrayList<>();
             ArrayList<Integer> y2 = new ArrayList<>();// odd pos pe even wale ko
             for(int i = 0; i<n; i++)
             {
                 if(arr[i]%2 == 0)
                 {
                     if(i%2 == 0)
                     {
                         y1.add(i);
                     }
                     else
                     {
                         x1.add(i);
                     }
                 }
                 else
                 {
                     if(i%2 == 0)
                     {
                       x2.add(i);
                     }
                     else
                     {
                        y2.add(i);
                     }
                 }
  
             }
             int ans1 = 0;
             int ans2 = 0;
             for(int j = 0; j<x1.size(); j++)
             {
                 ans1+= Math.abs(x1.get(j)-x2.get(j));
             }
             for(int j = 0; j<y1.size(); j++)
             {
                 ans2+=Math.abs(y1.get(j)-y2.get(j));
             }
             sb.append(Math.min(ans1,ans2)+"\n");
             return;
  
         }
         else if(even > odd)
         {
              ArrayList<Integer> x1 = new ArrayList<>();
             ArrayList<Integer> x2 = new ArrayList<>();// even pe even rhega
             for(int i = 0; i<n; i++)
             {
                 if(arr[i]%2 == 0)
                 {
                     if(i%2 != 0)
                     {
                         x1.add(i);
                     }
                 }
                 else
                 {
                     if(i%2 == 0)
                     {
                         x2.add(i);
                     }
                 }
             }
             int ans1 = 0;
            // int ans2 = 0;
             for(int j = 0; j<x1.size(); j++)
             {
                 ans1+=Math.abs(x1.get(j)-x2.get(j));
             }
             sb.append(ans1+"\n");
         }
         else
         {
             ArrayList<Integer> x1 = new ArrayList<>(); // odd pe even rhega
             ArrayList<Integer> x2 = new ArrayList<>(); // odd pe even rhega
             for(int i = 0; i<n; i++)
             {
                 if(arr[i]%2 == 0)
                 {
                     if(i%2 == 0)
                     {
                         x1.add(i);
                     }
                 }
                 else
                 {
                     if(i%2 != 0)
                     {
                         x2.add(i);
                     }
                 }
             }
             int ans1 = 0;
             // int ans2 = 0;
             for(int j = 0; j<x1.size(); j++)
             {
                 ans1+=Math.abs(x1.get(j)-x2.get(j));
             }
             sb.append(ans1+"\n");
         }
  
      }
  
  
      int gcd(int a, int b)
      {
          if (b == 0)
              return a;
          return gcd(b, a % b);
      }
      long gcd(long a, long b)
      {
          if (b == 0)
              return a;
          return gcd(b, a % b);
      }
      long power(long x, long y, long p)
      {
          long res = 1; // Initialize result
  
          // Update x if it is more
          // than or equal to p
          x = x % p;
  
          while (y > 0)
          {
              // If y is odd, multiply
              // x with the result
              if ((y & 1) > 0)
                  res = (res * x) % p;
  
              // y must be even now
              y = y >> 1; // y = y/2
              x = (x * x) % p;
          }
          return res;
      }
  
      int lower_bound(int [] arr , int key)
      {
  
          int i = 0;
          int j = arr.length-1;
          //if(arr[i] > key)return -1;
          if(arr[j] < key)return -1;
  
          while(i<j)
          {
              int mid = (i+j)/2;
  
              if(arr[mid] == key)
              {
                  j = mid;
              }
  
              else if(arr[mid] < key)
              {
                  i = mid+1;
              }
              else
                  j = mid-1;
          }
  
          return i;
      }
  
      int upper_bound(int [] arr , int key)
      {
  
          int i = 0;
          int j = arr.length-1;
          if(arr[j] <= key)return j+1;
  
          while(i<j)
          {
              int mid = (i+j)/2;
  
  
  
              if(arr[mid] <= key)
              {
                  i = mid+1;
              }
              else
                  j = mid;
          }
  
          return i;
      }
  
      
  
      int find(int dsu [],int i)
      {
          if(dsu[i] == i)
              return i;
          dsu[i] = find(dsu,dsu[i]);
          return dsu[i];
      }
  
      void  union(int dsu[] ,int i, int j)
      {
          int a = find(dsu,i);
          int b = find(dsu,j);
          dsu[a] = b;
      }
  
      static void sort(int[] A){
          int n = A.length;
          Random rnd = new Random();
          for(int i=0; i<n; ++i){
              int tmp = A[i];
              int randomPos = i + rnd.nextInt(n-i);
              A[i] = A[randomPos];
              A[randomPos] = tmp;
          }
          Arrays.sort(A);
      }
      static void sort(long[] A){
          int n = A.length;
          Random rnd = new Random();
          for(int i=0; i<n; ++i){
              long tmp = A[i];
              int randomPos = i + rnd.nextInt(n-i);
              A[i] = A[randomPos];
              A[randomPos] = tmp;
          }
          Arrays.sort(A);
      }
      static String sort(String s) {
          Character ch[]=new Character[s.length()];
          for(int i=0;i<s.length();i++) {
              ch[i]=s.charAt(i);
          }
          Arrays.sort(ch);
          StringBuffer st=new StringBuffer("");
          for(int i=0;i<s.length();i++) {
              st.append(ch[i]);
          }
          return st.toString();
      }
  
      //long array input
      public long [] longArr(int len)
      {
          // long arr input
          long [] arr = new long[len];
          String [] strs =  s.nextLine().trim().split("\\s+");
          for(int i =0; i<len; i++)
          {
              arr[i] = Long.parseLong(strs[i]);
  
          }
          return arr;
      }
      // int arr input
      public int [] intArr(int len)
      {
          // long arr input
          int [] arr = new int[len];
          String [] strs =  s.nextLine().trim().split("\\s+");
          for(int i =0; i<len; i++)
          {
              arr[i] = Integer.parseInt(strs[i]);
  
          }
          return arr;
      }
  
      static class FastReader
      {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader()
          {
              br = new BufferedReader(new
                      InputStreamReader(System.in));
          }
  
          String next()
          {
              while (st == null || !st.hasMoreElements())
              {
                  try
                  {
                      st = new StringTokenizer(br.readLine());
                  }
                  catch (IOException  e)
                  {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt()
          {
              return Integer.parseInt(next());
          }
  
          long nextLong()
          {
              return Long.parseLong(next());
          }
  
          double nextDouble()
          {
              return Double.parseDouble(next());
          }
  
          String nextLine()
          {
              String str = "";
              try
              {
                  str = br.readLine();
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
              return str;
          }
      }
  
  
  
  }
  