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.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.File;
  import java.io.*;
  import java.util.*;
  
  public class Main {
  
      // static final File ip = new File("input.txt");
      // static final File op = new File("output.txt");
      // static {
      //     try {
      //         System.setOut(new PrintStream(op));
      //         System.setIn(new FileInputStream(ip));
      //     } catch (Exception e) {
      //     }
      // }
      static long MOD = (long) 1e9 + 7;
  
      static int fun(int x, long[] arr) {
          int ans = 0;
          int delta = 0;
          for (int i = 0; i < arr.length; i++) {
              if (arr[i] != x)
                  delta += (x - arr[i]);
              ans += Math.abs(delta);
              x ^= 1;
          }
          return ans;
      }
  
      public static void main(String[] args) {
          FastReader sc = new FastReader();
          int test = sc.nextInt();
          while (test-- != 0) {
              int n = sc.nextInt();
              long[] a = new long[n];
              int[] f = new int[2];
              for (int i = 0; i < n; i++) {
                  a[i] = sc.nextLong();
                  a[i] = a[i] % 2;
                  if (a[i] == 0)
                      f[0]++;
                  else
                      f[1]++;
              }
              if(Math.abs(f[0]-f[1]) > 1) System.out.println("-1");
              else if (n % 2 == 0) {
                  if (f[0] == f[1]) {
                      int ans = Math.min(fun(0, a), fun(1, a));
                      System.out.println(ans);
                  } else
                      System.out.println("-1");
              } else {
                  if (f[0] == f[1] + 1)
                      System.out.println(fun(0, a));
                  else if (f[1] == f[0] + 1)
                      System.out.println(fun(1, a));
                  else
                      System.out.println("-1");
              }
  
          }
  
      }
  
      static long power(long x, long y, long p) {
          long res = 1;
          x = x % p;
          if (x == 0)
              return 0;
          while (y > 0) {
              if ((y & 1) != 0)
                  res = (res * x) % p;
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
  
      public static int countSetBits(long number) {
          int count = 0;
          while (number > 0) {
              ++count;
              number &= number - 1;
          }
          return count;
      }
  
      private static <T> void swap(int[] a, int i, int j) {
          int tmp = a[i];
          a[i] = a[j];
          a[j] = tmp;
      }
  
      static class pair {
          long a, b;
  
          pair(long x, long y) {
              this.a = x;
              this.b = y;
          }
          // public boolean equals(Object o) {
          // if (this == o) return true;
          // if (!(o instanceof pair)) return false;
          // pair key = (pair) o;
          // return a == key.a && b == key.b;
          // }
  
          // @Override
          // public int hashCode() {
          // int result = a;
          // result = 31 * result + b;
          // return result;
          // }
  
          // public int compare(pair p1, pair p2) {
          // if(p1.a - p2.a > 0) return -1;
          // if(p1.a - p2.a < 0) return 1;
          // return 0;
          // }
      }
  
      static class comparator implements Comparator<pair> {
  
          public int compare(pair p1, pair p2) {
              if (p1.a - p2.a > 0)
                  return 1;
              if (p1.a - p2.a < 0)
                  return -1;
              if (p1.a == p2.a) {
                  if (p1.b > p2.b)
                      return -1;
                  else if (p1.b < p2.b)
                      return 1;
              }
              return 0;
          }
      }
  
      private static long getSum(int[] array) {
          long sum = 0;
          for (int value : array) {
              sum += value;
          }
          return sum;
      }
  
      private static boolean isPrime(Long x) {
          if (x < 2)
              return false;
          for (long d = 2; d * d <= x; ++d) {
              if (x % d == 0)
                  return false;
          }
          return true;
      }
  
      static int[] reverse(int a[], int n) {
          int i, k, t;
          for (i = 0; i < n / 2; i++) {
              t = a[i];
              a[i] = a[n - i - 1];
              a[n - i - 1] = t;
          }
          return a;
      }
  
      private static boolean isPrimeInt(int x) {
          if (x < 2)
              return false;
          for (int d = 2; d * d <= x; ++d) {
              if (x % d == 0)
                  return false;
          }
          return true;
      }
  
      public static String reverse(String input) {
          StringBuilder str = new StringBuilder("");
  
          for (int i = input.length() - 1; i >= 0; i--) {
              str.append(input.charAt(i));
          }
  
          return str.toString();
      }
  
      private static int[] getPrimes(int n) {
          boolean[] used = new boolean[n + 1];
          used[0] = used[1] = true;
          int size = 0;
          for (int i = 2; i <= n; ++i) {
              if (!used[i]) {
                  ++size;
                  for (int j = 2 * i; j <= n; j += i) {
                      used[j] = true;
                  }
              }
          }
          int[] primes = new int[size];
          for (int i = 0, cur = 0; i <= n; ++i) {
              if (!used[i]) {
                  primes[cur++] = i;
              }
          }
          return primes;
      }
  
      private static long lcm(long a, long b) {
          return a / gcd(a, b) * b;
      }
  
      private static long gcd(long a, long b) {
          return (a == 0 ? b : gcd(b % a, a));
      }
  
      static void sortI(int[] arr) {
          int n = arr.length;
          Random rnd = new Random();
          for (int i = 0; i < n; ++i) {
              int tmp = arr[i];
              int randomPos = i + rnd.nextInt(n - i);
              arr[i] = arr[randomPos];
              arr[randomPos] = tmp;
          }
          Arrays.sort(arr);
      }
  
      static void shuffleList(ArrayList<Long> arr) {
          int n = arr.size();
          Random rnd = new Random();
          for (int i = 0; i < n; ++i) {
              long tmp = arr.get(i);
              int randomPos = i + rnd.nextInt(n - i);
              arr.set(i, arr.get(randomPos));
              arr.set(randomPos, tmp);
          }
      }
  
      static void factorize(long n) {
          int count = 0;
          while (!(n % 2 > 0)) {
              n >>= 1;
  
              count++;
          }
          if (count > 0) {
              // System.out.println("2" + " " + count);
          }
          long i = 0;
          for (i = 3; i <= (long) Math.sqrt(n); i += 2) {
              count = 0;
              while (n % i == 0) {
                  count++;
                  n = n / i;
              }
              if (count > 0) {
                  // System.out.println(i + " " + count);
              }
          }
  
          if (n > 2) {
              // System.out.println(i + " " + count);
          }
      }
  
      static void sortL(long[] arr) {
          int n = arr.length;
          Random rnd = new Random();
          for (int i = 0; i < n; ++i) {
              long tmp = arr[i];
              int randomPos = i + rnd.nextInt(n - i);
              arr[i] = arr[randomPos];
              arr[randomPos] = tmp;
          }
          Arrays.sort(arr);
      }
  
      static class FastReader {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader() {
              br = new BufferedReader(new InputStreamReader(System.in));
          }
  
          public boolean hasNext() {
              return false;
          }
  
          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;
          }
      }
  }