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: /**
   * @Created_by : Lucent868
   * @Date : 30-08-2021
   * @Time :  09:52
   */
  
  import java.util.*;
  import java.io.*;
  import java.math.*;
  
  public class B {
      static InputReader in;
      static PrintWriter out;
  
      public static void main(String args[]) {
          new Thread(null, new Runnable() {
              public void run() {
                  try {
                      solve();
                      out.flush();
                      out.close();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }, "1", 1 << 26).start();
      }
  
      public static void solve() {
          in = new InputReader(System.in);
          out = new PrintWriter(System.out);
  
          int t = in.nextInt();
          while (t-- > 0) {
  
              int n = in.nextInt();
              int a[] = in.nextIntArray(n);
  
              int o = 0;
              int e = 0;
              for (int i = 0; i < n; i++) {
                  if (a[i] % 2 == 0) e++;
                  else o++;
                  a[i] %= 2;
              }
              if (n == 1) {
                  out.println(0);
                  continue;
              }
  
              if (Math.abs(o - e) > 1) {
                  out.println(-1);
                  continue;
              }
              ArrayList<Integer> even = new ArrayList<>();
              ArrayList<Integer> odd = new ArrayList<>();
  
              int b[] = new int[n];
              for (int i = 1; i < n; i += 2) {
                  b[i] = 1;
              }
              int c[] = new int[n];
              for (int i = 0; i < n; i += 2) {
                  c[i] = 1;
              }
  
              int ans1 = 0;
              for (int i = 0; i < n; i++) {
                  if (b[i] == 1 && a[i] == 0)
                      odd.add(i);
                  else if (b[i] == 0 && a[i] == 1)
                      even.add(i);
  
              }
  
  
              if (even.size() == odd.size()) {
                  for (int i = 0; i < even.size(); i++)
                      ans1 += Math.abs(even.get(i) - odd.get(i));
              } else {
                  ans1 = Integer.MAX_VALUE;
              }
  //            out.println(even + " " + odd);
              even.clear();
              odd.clear();
              int ans2 = 0;
              for (int i = 0; i < n; i++) {
                  if (c[i] == 1 && a[i] == 0)
                      odd.add(i);
                  else if (c[i] == 0 && a[i] == 1)
                      even.add(i);
  
              }
  
              if (even.size() == odd.size())
              {       for (int i = 0; i < even.size(); i++)
                      ans2 += Math.abs(even.get(i) - odd.get(i));
              }
              else
              {
                  ans2 = Integer.MAX_VALUE;
              }
  //            out.println(even+" "+odd);
  
              out.println(Math.min(ans1,ans2));
  
          }
      }
  
      static class InputReader {
          private final InputStream stream;
          private final byte[] buf = new byte[8192];
          private int curChar, numChars;
          private SpaceCharFilter filter;
  
          public InputReader(InputStream stream) {
              this.stream = stream;
          }
  
          public int read() {
              if (numChars == -1) {
                  throw new InputMismatchException();
              }
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
                  } catch (IOException e) {
                      throw new InputMismatchException();
                  }
                  if (numChars <= 0) {
                      return -1;
                  }
              }
              return buf[curChar++];
          }
  
          public String nextLine() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isEndOfLine(c));
              return res.toString();
          }
  
          public String readString() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
          public long nextLong() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              long res = 0;
              do {
                  if (c < '0' || c > '9') {
                      throw new InputMismatchException();
                  }
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public int nextInt() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              int res = 0;
              do {
                  if (c < '0' || c > '9') {
                      throw new InputMismatchException();
                  }
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public int[] nextIntArray(int n) {
              int[] arr = new int[n];
              for (int i = 0; i < n; i++) {
                  arr[i] = nextInt();
              }
              return arr;
          }
  
          public long[] nextLongArray(int n) {
              long[] arr = new long[n];
              for (int i = 0; i < n; i++) {
                  arr[i] = nextLong();
              }
              return arr;
          }
  
          public boolean isSpaceChar(int c) {
              if (filter != null)
                  return filter.isSpaceChar(c);
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          private boolean isEndOfLine(int c) {
              return c == '\n' || c == '\r' || c == -1;
          }
  
          public interface SpaceCharFilter {
              public boolean isSpaceChar(int ch);
          }
      }
  
      public static int[] sort(int[] arr) {
          List<Integer> temp = new ArrayList();
          for (int i : arr) temp.add(i);
          Collections.sort(temp);
          int start = 0;
          for (int i : temp) arr[start++] = i;
          return arr;
      }
  
      public static long[] sort(long[] arr) {
          List<Long> temp = new ArrayList();
          for (long i : arr) temp.add(i);
          Collections.sort(temp);
          int start = 0;
          for (long i : temp) arr[start++] = i;
          return arr;
      }
  
      public static int bs(int[] a, int fromIndex, int toIndex,
                           double key) {
          int low = fromIndex;
          int high = toIndex - 1;
  
          while (low <= high) {
              int mid = (low + high) >>> 1;
              long midVal = a[mid];
  
              if (midVal < key)
                  low = mid + 1;
              else if (midVal > key)
                  high = mid - 1;
              else
                  return mid; // key found
          }
          return -(low + 1);  // key not found.
      }
  
  }
  