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 math
  import sys
  #-----------------------IMPORTANT  FUNCTIONS ---------------------------------#
  from math import cos, pi, ceil, pi, tan, floor, gcd, sqrt, log2, factorial, log10
  from collections import Counter
  from copy import deepcopy
  from string import ascii_lowercase, ascii_uppercase
  from statistics import mean, median, mode
  
  alpha = ascii_lowercase
  beta = ascii_uppercase
  
  
  #-----------------------NEXT POWER OF 2---------------------------------------#
  def nextPowerOf2(n):
      p = 1
      if (n and not (n & (n - 1))):
          return n
      while (p < n):
          p <<= 1
      return p
  
  
  #-----------------------GET DIVISORS 1 TO <=N   ------------------------------#
  def get_Divisors(n):
      arr = []
      i = 1
      while i <= sqrt(n):
          if (n % i == 0):
              if (n / i == i):
                  arr.append(i)
              else:
                  arr.append(i)
                  arr.append(n // i)
          i = i + 1
  
      return arr
  
  
  #----------------------CHECK    PRIMES-----------------------------------#
  def isprime(n):
      if n == 1:
          return 0
      i = 2
      while (i * i <= n):
          if (n % i == 0):
              return 0
          i += 1
      return 1
  
  
  #-----------------------PRE COMPUTED  PRIMES-----------------------------------#
  def Sieve(n):
      prime = [True for i in range(n + 1)]
      prime[0] = False
      prime[1] = False
      p = 2
      while (p * p <= n):
          if (prime[p] == True):
              for i in range(p * p, n + 1, p):
                  prime[i] = False
          p += 1
      return prime
  
  
  #-----------------------LARGER VALUE OF  X,Y,10**9+7 --------------------------#
  def power(x, y, p):
      res = 1
      x = x % p
      if (x == 0):
          return 0
      while (y > 0):
          if ((y & 1) == 1):
              res = (res * x) % p
          y = y >> 1
          x = (x * x) % p
      return res
  
  
  #-----------------------       CREATE MATRIX         --------------------------#
  def create_matrix(n, m):
      mat = [[] for i in range(n)]
      for i in range(n):
          for j in range(m):
              mat[i].append(0)
      return mat
  
  
  #By Default Counter stores the value in decending orderCounter({4: 2, 8: 2, 2: 1, 9: 1}
  #s=sorted(s.items(),key=lambda k:(k[0],k[1])) ---> [(2, 1), (4, 2), (8, 2), (9, 1)]
  #sort 2nd value  from bada se chhota  then(4,2)(8,2)->>(8,2)(4,2) s=sorted(s.items(),key=lambda k:(-k[1],-k[0]))  [(8, 2), (4, 2), (9, 1), (2, 1)]
  #for list pair in a list    s.sort(key=lambda k:(-k[1],-k[0])) [[3, 4], [8, 2], [4, 2]]
  # from functools import cmp_to_key
  # def compare(x, y):
  #     if x + y > y + x:
  #         return -1
  #     elif x + y < y + x:
  #         return 1
  #     else:
  #         return 0
  #how to use compare ----ss = sorted(s, key=cmp_to_key(compare))
  # a=[1,4,5,9,12,15]
      # print(bisect(a,9))
      # insort(a,9)
      # print(a)  
      #arr=[-14,-10,2,108,108,243,285,285,401]
      # print(bisect_left(arr,-10))                 
      # print(bisect_left(arr,108))                 
      # print(bisect_left(arr,501))                 
      # print(bisect_left(arr,200))                 
      # print(bisect_left(arr,-20))
      #**************************************                 
      # print(bisect_right(arr,-10))                 
      # print(bisect_right(arr,108))                 
      # print(bisect_right(arr,501))                 
      # print(bisect_right(arr,200))                 
      # print(bisect_right(arr,-20)) 
  # #-----------------------*****CODE STARTS  HERE*****--------------------------#
  # sys.stdout = open('ot.txt', 'w')
  # sys.stdin = open('in.txt', 'r')
  from bisect import *
  def main():
      for tt in range(int(input())):
          n=int(input())
          arr=list(map(int,input().split())) 
          o=0 
          e=0 
          for i in arr:
              if i%2==0:
                  e+=1 
              else:
                  o+=1 
          if abs(o-e)>1:
              print(-1)
          elif o>e:
              odd=[]
              even=[]
              for i in range(n):
                  if (i+1)%2==1  and arr[i]%2==0:
                      odd.append(i)
                  elif ((i+1)%2==0  and arr[i]%2==1):
                      even.append(i)
              ans=0 
              for i in range(len(odd)):
                  ans+=abs(odd[i]-even[i])
              print(ans)
          elif o<e:
              odd=[]
              even=[]
              for i in range(n):
                  if (i)%2==0  and arr[i]%2==1:
                      even.append(i)
                  elif (i%2==1  and arr[i]%2==0):
                      odd.append(i)
              ans=0 
              for i in range(len(odd)):
                  ans+=abs(odd[i]-even[i])
              print(ans)
          else:
              od=[]
              odd=[]
              ev=[]
              even=[]
              ans1,ans2=0,0
              for i in range(n):
                  if i%2==0 and arr[i]%2:
                      ev.append(i)
                  elif i%2 and arr[i]%2==0:
                      od.append(i)
              for i in range(len(od)):
                  ans1+=abs(od[i]-ev[i])
              for i in range(n):
                  if (i+1)%2==0 and arr[i]%2:
                      even.append(i)
                  elif (i+1)%2 and arr[i]%2==0:
                      odd.append(i)
              for i in range(len(odd)):
                  ans2+=abs(odd[i]-even[i])
              print(min(ans1,ans2)) 
  if __name__ == "__main__":
      main()