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.util.Map.Entry;
  import java.lang.*;
  import java.io.*;
  import java.math.BigInteger;
  
  public class CF {
  	private static FS sc = new FS();
  	
  	private static class FS {
  		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st = new StringTokenizer("");
  		String next() {
  			while (!st.hasMoreTokens())
  				try {
  					st=new StringTokenizer(br.readLine());				               
  	            } catch (IOException e) {}
  			return st.nextToken();
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
  	
  	private static class extra {
  		
  		static int[] intArr(int size) {
  			int[] a = new int[size];
  			for(int i = 0; i < size; i++) a[i] = sc.nextInt();
  			return a;
  		}
  		
  		static long[] longArr(int size) {
  			long[] a = new long[size];
  			for(int i = 0; i < size; i++) a[i] = sc.nextLong();
  			return a;
  		}
  		
  		static long intSum(int[] a) {
  			long sum = 0; 
  			for(int i = 0; i < a.length; i++) {
  				sum += a[i];
  			}
  			return sum;
  		}
  		
  		static long longSum(long[] a) {
  			long sum = 0; 
  			for(int i = 0; i < a.length; i++) {
  				sum += a[i];
  			}
  			return sum;
  		}
  		
  		static LinkedList[] graphD(int vertices, int edges) {
  			LinkedList<Integer>[] temp = new LinkedList[vertices+1];
  			for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>();
  			for(int i = 0; i < edges; i++) {
  				int x = sc.nextInt();
  				int y = sc.nextInt();
  				temp[x].add(y);
  			}
  			return temp;
  		}
  		
  		static LinkedList[] graphUD(int vertices, int edges) {
  			LinkedList<Integer>[] temp = new LinkedList[vertices+1];
  			for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>();
  			for(int i = 0; i < edges; i++) {
  				int x = sc.nextInt();
  				int y = sc.nextInt();
  				temp[x].add(y);
  				temp[y].add(x);
  			}
  			return temp;
  		}
  		
  		static void printG(LinkedList[] temp) {
  			for(LinkedList<Integer> aa:temp) System.out.println(aa);
  		}
  		
  		static long cal(long val, long pow) {
  			if(pow == 0) return 1;
  			long res = cal(val, pow/2);
  			
  			long ret = (res*res)%mod;
  			if(pow%2 == 0) return ret;
  			return (val*ret)%mod;
  		}
  		
  		static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); }
  		
  	}
  	
  	static int mod = (int) 1e9 + 7;
  //	static int mod = (int) 998244353;
  	//static int max = (int) 1e6;//, sq = 316;
  	static LinkedList<Integer>[] temp;
  	static double ans;
  	
  	public static void main(String[] args) {	
  		int t = sc.nextInt();
  //		int t = 1;
  		StringBuilder ret = new StringBuilder();
  //		int k = 1;
  		while(t-- > 0) {
  			int n = sc.nextInt();
  			int[] a = extra.intArr(n);
  			int z = 0, o = 0;
  			for(int i = 0; i < n; i++) {
  				a[i] %= 2;
  				if(a[i] == 0) z++;
  				else {
  					o++;
  				}
  			}
  			if(n == 1) {
  				ret.append(0 + "\n");
  				continue;
  			}
  //			System.out.println(z + " " + o);
  			if(Math.abs(z-o) <= 1) {
  //				1 0 1 0 1
  				if(z == o) {
  					int ans1 = 0;
  					LinkedList<Integer> set = new LinkedList<>();
  					for(int i = 0; i < n; i += 2) set.add(i);
  //					System.out.println(set);
  					for(int i = 0; i < n; i++) {
  						if(a[i] == 1) {
  							ans1 += Math.abs(set.poll()-i);
  						} 
  					}
  					set = new LinkedList<>();
  					int ans2 = 0;
  					for(int i = n-1; i >= 0; i -= 2) set.add(i);
  					for(int i = n-1; i >= 0; i--) {
  						if(a[i] == 1) {
  							ans2 += Math.abs(set.poll()-i);
  						} 
  					}
  //					System.out.println(ans1 + " " + ans2);
  					ret.append(Math.min(ans1, ans2) + "\n");
  				} else if(z > o) {
  					int ans = 0;
  					LinkedList<Integer> set = new LinkedList<>();
  					for(int i = 1; i < n; i += 2) set.add(i);
  //					System.out.println(set);
  					for(int i = 0; i < n; i++) {
  						if(a[i] == 1) {
  							ans += Math.abs(set.poll()-i);
  						} 
  					}
  					ret.append(ans + "\n");
  				} else {
  					int ans = 0;
  					LinkedList<Integer> set = new LinkedList<>();
  					for(int i = 0; i < n; i += 2) set.add(i);
  //					System.out.println(set);
  					for(int i = 0; i < n; i++) {
  						if(a[i] == 1) {
  							ans += Math.abs(set.poll()-i);
  						} 
  					}
  					ret.append(ans + "\n");
  				}
  			} else ret.append(-1 + "\n");
  			
  		}
  		System.out.println(ret);
  	}
  	
  }
  
  
  
  
  