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 static java.lang.Math.max;
  import static java.lang.Math.min;
  import static java.lang.Math.abs;
  import static java.lang.System.out;
  import java.util.* ;
  import java.math.*;
  import java.io.*;
  
  
   public class javaTemplate {
  	
  	public static final int M = 1000000007 ;
  	static FastReader sc = new FastReader();
  	static int N = 86028121 ;
  	static boolean globB[] = new boolean[N+1] ;
  	static int globA[] = new int[10000000] ;
  	
  	
  	public static void main(String[] args) {
  		
  int t = sc.nextInt() ;
  		
  		while(t -- != 0) {
  			int n = sc.nextInt() ;
  			int a[] = new int[n] ;
  			int odd = 0 ;
  			int even = 0 ;
  			int copy[] = new int[n] ;
  			boolean val = true ;
  			ArrayList<Integer> e = new ArrayList<>() ;
  			ArrayList<Integer> o = new ArrayList<>() ;
  			for(int i = 0 ; i< n ; i++) {
  				a[i] = sc.nextInt()%2 ;
  				if(a[i] == 1) odd ++ ;
  				else even ++ ;
  			}
  			
  			int ans = 0 ;
  			
  			if(even > odd && Math.abs(even-odd) <= 1) {
  				for(int i = 0 ; i< n ; i++) {
  					if(val) {
  						copy[i] = 0 ;
  						val = false ;
  					} else {
  						copy[i] = 1 ;
  						val = true ;
  					}
  				}
  				
  				for(int i = 0 ; i< n ; i++) {
  					if(a[i] != copy[i] && copy[i] == 1) {
  						o.add(i) ;
  					} else if(a[i] != copy[i] && copy[i] == 0) {
  						e.add(i) ;
  					}
  				}
  				
  				for(int i = 0 ; i< o.size() ; i++) {
  					ans += Math.abs(o.get(i)-e.get(i)) ;
  				}
  			} else if(even < odd && Math.abs(even-odd) <= 1) {
  				for(int i = 0 ; i< n ; i++) {
  					if(val) {
  						copy[i] = 1 ;
  						val = false ;
  					} else {
  						copy[i] = 0 ;
  						val = true ;
  					}
  				}
  				
  				for(int i = 0 ; i< n ; i++) {
  					if(a[i] != copy[i] && copy[i] == 1) {
  						o.add(i) ;
  					} else if(a[i] != copy[i] && copy[i] == 0) {
  						e.add(i) ;
  					}
  				}
  				
  				for(int i = 0 ; i< o.size() ; i++) {
  					ans += Math.abs(o.get(i)-e.get(i)) ;
  				}
  			} else if(Math.abs(even-odd) <= 1){
  				for(int i = 0 ; i< n ; i++) {
  					if(val) {
  						copy[i] = 1 ;
  						val = false ;
  					} else {
  						copy[i] = 0 ;
  						val = true ;
  					}
  				}
  				
  				for(int i = 0 ; i< n ; i++) {
  					if(a[i] != copy[i] && copy[i] == 1) {
  						o.add(i) ;
  					} else if(a[i] != copy[i] && copy[i] == 0) {
  						e.add(i) ;
  					}
  				}
  				
  				int ans1 = 0 ;
  				for(int i = 0 ; i< o.size() ; i++) {
  					ans += Math.abs(o.get(i)-e.get(i)) ;
  				}
  				
  				val = true ;
  				for(int i = 0 ; i< n ; i++) {
  					if(val) {
  						copy[i] = 0 ;
  						val = false ;
  					} else {
  						copy[i] = 1 ;
  						val = true ;
  					}
  				}
  				
  				o.clear();
  				e.clear();
  				for(int i = 0 ; i< n ; i++) {
  					if(a[i] != copy[i] && copy[i] == 1) {
  						o.add(i) ;
  					} else if(a[i] != copy[i] && copy[i] == 0) {
  						e.add(i) ;
  					}
  				}
  				
  				for(int i = 0 ; i< o.size() ; i++) {
  					ans1 += Math.abs(o.get(i)-e.get(i)) ;
  				}
  				
  				ans = min(ans,ans1) ;
  				
  			}
  			
  			
  			
  			
  			
  			
  			if(Math.abs(even-odd) > 1) {
  				System.out.println("-1");
  			} else {
  				System.out.println(ans);
  			}
  		}
  	}
  
  
  	/*
  	 @ Observation is imp. for problem A and B
  	 1->> Read the problem properly take time to read the problem 
  	 if it is too lengthy.
  	 2->> Draw the test cases of A and B 
  	 3->> Don't over think the problem 
  	 4->> Try to take sum variable as long
  	 5->> Avoid Nested if else statement
  	 6->> If it looks like a Greedy problem try to figure out the ans. 
  	 for the smallest test case.
  	 7->> If it is a binary String check no. of 0's and 1's. 
  	 If it is a even try to pair it (may be not applicable for every questions).
  	 8->> Always check the constrains and try BruteForce
  	 @ Implement it quickly 
  	 */
  	
  
  	
  	
  	
  
  
  	
  	
  //_________________________//Template//_____________________________________________________________________
  	
  	
  		//		FAST I/O
  		static class FastReader {
  	        BufferedReader br;
  	        StringTokenizer st;
  	        
  	        public FastReader()
  	        {
  	            br = new BufferedReader(
  	                new InputStreamReader(System.in));
  	        }
  	 
  	        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;
  	        }
  		}
  	
  	
  		
  		
  		
  		// Sorting
  		public static void sort(int[] arr) {
  	        //because Arrays.sort() uses quicksort which is dumb
  	        //Collections.sort() uses merge sort
  	        ArrayList<Integer> ls = new ArrayList<Integer>();
  	        for(int x: arr)
  	            ls.add(x);
  	        Collections.sort(ls);
  	        for(int i=0; i < arr.length; i++)
  	            arr[i] = ls.get(i);
  	    }
  		
  		
  		
  		
  		
  		// Modulo
  		static int mod(int a) {
  		   return (a%M + M) % M;
  		}
  		
  		
  		
  		
  		
  		
  		
  		//		Palindrom or Not
  		static boolean isPalindrome(String str, int low, int high) {
  					while (low < high) {
  						if (str.charAt(low) != str.charAt(high)) return false;
  					 	low++;
  					 	high--;
  					}
  					return true;
  				}
  	
  	
  
  	
  	
  	
  	
  	
  	
  	
  	
  		// check if sorted or not	
  		public static boolean isSorted(int[] a)
  	    {
  	        for (int i = 0; i < a.length - 1; i++)
  	        {
  	            if (a[i] > a[i + 1]) {
  	                return false;
  	            }
  	        }
  	        return true;
  	    }
  	
  	
  	
  		
  		
  	
  		// GCD
  		public static int GCD(int a , int b) {
  				if(b == 0) return a ;
  				
  				return GCD(b, a%b) ;
  			}
  	
  		
  		
  		
  		
  		// sieve
  		public static void sieve() {
  			Arrays.fill(globB, true);
  			globB[0] = false ;
  			globB[1] = false ;
  			for(int i = 2 ; i * i <= N ; i++) {
  				if(globB[i]) {
  				for(int j = i * i ; j<= N ; j+= i) {
  					globB[j] = false ;
  				 }
  				}
  			}
  			
  		}
  
  		
  		
  		
  		// fastPower
  		public static long fastPowerModulo(long a, long b, long n) {
  			long res = 1 ;
  			while(b > 0) {
  			if((b&1) != 0) {
  				res = (res * a % n) % n ;
  			}
  			a = (a % n * a % n) % n ;
  			b = b >> 1 ;
  			}
  			return res ;
  		}
  	
  		
  		
          // LCM
  		static int LCM(int a, int b)
  	    {
  	        return (a / GCD(a, b)) * b;
  	    }
  		
  
  }
  
  
   
   
   
   
   
   
  