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.util.*;
  import java.lang.*;
  import java.io.*;
  
  public class BDeltix {
      public static void main(String[] args) throws java.lang.Exception {
          // your code goes here
          //try {
              // Scanner sc=new Scanner(System.in);
              FastReader sc = new FastReader();
              int t =sc.nextInt();
              while (t-- > 0) {
                  int n=sc.nextInt();
                  int[] arr=new int[n];
                  int[] arr1=new int[n];
                  int ec=0;
                  int oc=0;
                  for(int i=0;i<n;i++){
                      arr[i]=sc.nextInt();
                      arr1[i]=arr[i];
                      if(arr[i]%2==0){
                          ec++;
                      }
                      else{
                          oc++;
                      }
                  }
                  boolean pos=true;
                  if(n%2==0 && ec!=oc){
                      System.out.println(-1);
                      pos=false;
                  }
                  else if(n%2==1 && Math.abs(ec-oc)>1){
                      System.out.println(-1);
                      pos=false;
                  }
                  if(!pos)continue;
                  
                  int cnt=0;
                  if(n%2==0){
                      //even position even value
                      int s=0;
                      for(int i=0;i<n;i++){
                          if(arr[i]%2==0){
                              cnt+=Math.abs(i-s);
                              s+=2;
                          }
                      }
                      //even values odd position
                      s=1;
                      int cnt1=0;
                      for(int i=0;i<n;i++){
                          if(arr[i]%2==0){
                              cnt1+=Math.abs(i-s);
                              s+=2;
                          }
                      }
                      cnt=Math.min(cnt,cnt1);
  
  
                  }
                  else{
                      if(ec>oc){
                          //even position even values
                          int s=0;
                          for(int i=0;i<n;i++){
                              if(arr[i]%2==0){
                                  cnt+=Math.abs(i-s);
                                  s+=2;
                              }
                          }
                      }
                      else{
                          //even position odd values i.e even values odd position
                          int s=1;
                          for(int i=0;i<n;i++){
                              if(arr[i]%2==0){
                                  cnt+=Math.abs(i-s);
                                  s+=2;
                              }
                          }
                      }
                  }
                  System.out.println(cnt);
                  
              }
         /* } catch (Exception e) {
              return;
          }*/
  
      }
      public static void swap(int[] arr,int i,int j){
          int temp=arr[i];
          arr[i]=arr[j];
          arr[j]=temp;
      }
      public static class pair{
          int ff;
          int ss;
          pair(int ff,int ss){
              this.ff=ff;
              this.ss=ss;
          }
      }
  
      static int BS(int[] arr, int l, int r, int element) {
          int low = l;
          int high = r;
          while (high - low > 1) {
              int mid = low + (high - low) / 2;
              if (arr[mid] < element) {
                  low = mid + 1;
              } else {
                  high = mid;
              }
          }
          if (arr[low] == element) {
              return low;
          } else if (arr[high] == element) {
              return high;
          }
          return -1;
      }
  
      static int lower_bound(int[] arr, int l, int r, int element) {
          int low = l;
          int high = r;
          while (high - low > 1) {
              int mid = low + (high - low) / 2;
              if (arr[mid] < element) {
                  low = mid + 1;
              } else {
                  high = mid;
              }
          }
          if (arr[low] >= element) {
              return low;
          } else if (arr[high] >= element) {
              return high;
          }
          return -1;
      }
  
      static int upper_bound(int[] arr, int l, int r, int element) {
          int low = l;
          int high = r;
          while (high - low > 1) {
              int mid = low + (high - low) / 2;
              if (arr[mid] <= element) {
                  low = mid + 1;
              } else {
                  high = mid;
              }
          }
          if (arr[low] > element) {
              return low;
          } else if (arr[high] > element) {
              return high;
          }
          return -1;
      }
      public static long gcd_long(long a,long b){
          //a/b,a-> dividant b-> divisor
          if(b==0)return a;
          return gcd_long(b, a%b);
      }
      public static int gcd_int(int a,int b){
          //a/b,a-> dividant b-> divisor
          if(b==0)return a;
          return gcd_int(b, a%b);
      }
      public static int lcm(int a,int b){
          int gcd=gcd_int(a, b);
          return (a*b)/gcd;
      }
  
      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());
          }
  
          String nextLine() {
              String s = "";
              try {
                  s = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return s;
          }
  
          Long nextLong() {
              return Long.parseLong(next());
          }
      }
  }
  
  /*
   * public static boolean lie(int n,int m,int k){ if(n==1 && m==1 && k==0){
   * return true; } if(n<1 || m<1 || k<0){ return false; } boolean
   * tc=lie(n-1,m,k-m); boolean lc=lie(n,m-1,k-n); if(tc || lc){ return true; }
   * return false; }
   */
  