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.DataInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.*;
  public class Scratch {
      public static int ceil(int p, int q)
      {
          if (p%q==0)
              return p/q;
          else
          return p/q+1;
      }
      public static void main(String[] args) throws IOException {
          Reader sc=new Reader();
          int p=sc.nextInt();
          for (int q=0;q<p;q++)
          {
              int n=sc.nextInt();
              int[] arr=new int[n];
              for (int r=0;r<n;r++)
                  arr[r]=sc.nextInt();
              ArrayList<Integer> eve=new ArrayList<>();
              ArrayList<Integer> odd=new ArrayList<>();
              int e=0;
              int o=0;
              for (int i=0;i<n;i++)
              {
                  if (arr[i]%2==0)
                  {
                      e+=1;
                      eve.add(i);
                  }
                  else
                  {
                      o+=1;
                      odd.add(i);
                  }
              }
              if (e>ceil(n,2) || o>ceil(n,2))
                  System.out.println(-1);
              else if (n%2==0)
              {
                  int ans1=0;
                  int ans2=0;
                  for (int i=0;i<eve.size();i++)
                  {
                      ans1+=Math.abs(2*(i)-eve.get(i));
                  }
                  for (int i=0;i<odd.size();i++)
                  {
                      ans2+=Math.abs(2*(i)-odd.get(i));
                  }
                  System.out.println(Math.min(ans1,ans2));
  
              }
              else
              {
                  int ans1=0;
  
                  if (eve.size()>odd.size())
                      for (int i=0;i<eve.size();i++)
                      {
                          ans1+=Math.abs(2*(i)-eve.get(i));
                      }
                  else
                      for (int i=0;i<odd.size();i++)
                      {
                          ans1+=Math.abs(2*(i)-odd.get(i));
                      }
                  System.out.println(ans1);
  
              }
  
  
  
          }
  
      }
      static class Reader
      {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Reader()
          {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Reader(String file_name) throws IOException
          {
              din = new DataInputStream(new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException
          {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1)
              {
                  if (c == '\n')
                      break;
                  buf[cnt++] = (byte) c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextInt() throws IOException
          {
              int ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do
              {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          public long nextLong() throws IOException
          {
              long ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              }
              while ((c = read()) >= '0' && c <= '9');
              if (neg)
                  return -ret;
              return ret;
          }
  
          public double nextDouble() throws IOException
          {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
  
              do {
                  ret = ret * 10 + c - '0';
              }
              while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.')
              {
                  while ((c = read()) >= '0' && c <= '9')
                  {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          private void fillBuffer() throws IOException
          {
              bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
              if (bytesRead == -1)
                  buffer[0] = -1;
          }
  
          private byte read() throws IOException
          {
              if (bufferPointer == bytesRead)
                  fillBuffer();
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException
          {
              if (din == null)
                  return;
              din.close();
          }
  
  
  
      }
  
  
      // Function to return gcd of a and b
  
  
  
  }
  