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.io.*;
  public class Test {
  	static Scanner sc=new Scanner(System.in);
  	static PrintWriter pw=new PrintWriter(System.out);
  	static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
  	public static void main(String []args) throws IOException {
  	int t=sc.nextInt();
  	while(t-->0) {
  		int n=sc.nextInt();
  		int [] a=new int [n];
  		int counteven=0,countodd=0;
  		int p1=0,p2=0,p3=0,p4=0;
  		for(int i=0;i<n;i++) {
  			a[i]=sc.nextInt();
  			if(a[i]%2==0) {
  				counteven++;
  			}
  			else {
  				countodd++;
  			}
  		}
  		if(counteven>countodd) {
  			p1=0;p2=1;
  		}
  		else if(counteven==countodd) {
  			p1=0;p2=1;p3=1;p4=0;
  		}
  		else {
  			p1=1;p2=0;
  		}
  		int [] ans=new int [n],ans2=new int [n];
  		for(int i=0;i<n;i++) {
  			if(a[i]%2==0) {
  				ans[i]=p1;
  				p1+=2;
  			}
  			else {
  				ans[i]=p2;
  				p2+=2;
  			}
  			if(n%2==0) {
  				if(a[i]%2==0) {
  					ans2[i]=p3;
  					p3+=2;
  				}
  				else {
  					ans2[i]=p4;
  					p4+=2;
  				}
  			}
  		}
  		boolean f=true;
  		if(n%2==0) {
  			if(counteven==countodd) {
  				f=false;
  			}
  		}
  		else {
  			if(Math.abs(counteven-countodd)==1)
  				f=false;
  		}
  		if(f)
  			pw.println(-1);
  		else {
  			count=0;
  			//pw.println(Arrays.toString(ans));
  			mergesort(ans);
  			long x=count;
  			if(n%2!=0)
  				pw.println(x);
  			else {
  				count=0;
  				//pw.println(Arrays.toString(ans2));
  				mergesort(ans2);
  				pw.println(Math.min(count, x));
  			}
  			
  		}
  		
  	}
  		
  	pw.flush();
  	}
  		
  	static long count;
  	public static void merge(int []a,int start,int mid,int end) {
  		int []b=new int[end-start+1];
  		int ind1=start,ind2=mid+1;
  		int cur=0;
  		while(ind1<mid+1 || ind2<end+1) {
  			if(ind1==mid+1) {
  				for(;ind2<end+1;ind2++) {
  					b[cur++]=a[ind2];
  					
  				}
  			}
  			else if(ind2==end+1) {
  				for(;ind1<mid+1;ind1++) {
  					b[cur++]=a[ind1];
  				}
  			}
  			else {
  				if(a[ind1]>a[ind2]) {
  					b[cur++]=a[ind2++];
  					count+=mid-ind1+1;
  				}
  				else {
  					b[cur++]=a[ind1++];
  				}
  			}
  		}
  		for(int i=0;i<b.length;i++) {
  			a[i+start]=b[i];
  		}
  	}
  	public static void sort(int []a,int start,int end ) {
  		if(end==start)
  			return;
  		int mid=(start+end)/2;
  		sort(a, start, mid);
  		sort(a, mid+1, end);
  		merge(a, start, mid, end);
  		//pw.println(Arrays.toString(s));
  	}
  	public static void mergesort(int []a) {
  		sort(a, 0, a.length-1);
  	}
  	static long count2=0;
  	public static void insertionSort(int []a) {
  		int n=a.length;
  		for(int i=1;i<n;i++) {
  			int j=i-1;
  			int key=a[i];
  			while(j>-1 && a[j]>key) {
  				a[j+1]=a[j];
  				j--;
  				//count2++;
  			}
  			a[j+1]=key;
  			
  		}
  	}
  	static class pair implements Comparable<pair> {
  		long x;
  		long y;
   
  		public pair(long x, long y) {
  			this.x = x;
  			this.y = y;
  		}
   
  		public String toString() {
  			return x + " " + y;
  		}
   
  		public boolean equals(Object o) {
  			if (o instanceof pair) {
  				pair p = (pair) o;
  				return p.x == x && p.y == y;
  			}
  			return false;
  		}
   
  		public int hashCode() {
  			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
  		}
   
  		public int compareTo(pair other) {
  			if (this.x == other.x) {
  				return Long.compare(this.y, other.y);
  			}
  			return Long.compare(this.x, other.x);
  		}
  	}
  	static class Scanner {
  		StringTokenizer st;
  		BufferedReader br;
   
  		public Scanner(InputStream s) {
  			br = new BufferedReader(new InputStreamReader(s));
  		}
   
  		public Scanner(FileReader r) {
  			br = new BufferedReader(r);
  		}
  		public String readAllLines(BufferedReader reader) throws IOException {
  		    StringBuilder content = new StringBuilder();
  		    String line;
  		    
  		    while ((line = reader.readLine()) != null) {
  		        content.append(line);
  		        content.append(System.lineSeparator());
  		    }
   
  		    return content.toString();
  		}
  		public String next() throws IOException {
  			while (st == null || !st.hasMoreTokens())
  				st = new StringTokenizer(br.readLine());
  			return st.nextToken();
  		}
   
  		public int nextInt() throws IOException {
  			return Integer.parseInt(next());
  		}
   
  		public long nextLong() throws IOException {
  			return Long.parseLong(next());
  		}
   
  		public String nextLine() throws IOException {
  			return br.readLine();
  		}
   
  		public double nextDouble() throws IOException {
  			String x = next();
  			StringBuilder sb = new StringBuilder("0");
  			double res = 0, f = 1;
  			boolean dec = false, neg = false;
  			int start = 0;
  			if (x.charAt(0) == '-') {
  				neg = true;
  				start++;
  			}
  			for (int i = start; i < x.length(); i++)
  				if (x.charAt(i) == '.') {
  					res = Long.parseLong(sb.toString());
  					sb = new StringBuilder("0");
  					dec = true;
  				} else {
  					sb.append(x.charAt(i));
  					if (dec)
  						f *= 10;
  				}
  			res += Long.parseLong(sb.toString()) / f;
  			return res * (neg ? -1 : 1);
  		}
   
  		public long[] nextlongArray(int n) throws IOException {
  			long[] a = new long[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextLong();
  			return a;
  		}
   
  		public Long[] nextLongArray(int n) throws IOException {
  			Long[] a = new Long[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextLong();
  			return a;
  		}
   
  		public int[] nextIntArray(int n) throws IOException {
  			int[] a = new int[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextInt();
  			return a;
  		}
   
  		public Integer[] nextIntegerArray(int n) throws IOException {
  			Integer[] a = new Integer[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextInt();
  			return a;
  		}
   
  		public boolean ready() throws IOException {
  			return br.ready();
  		}
   
  	}
  }
  