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: //This code is written by प्रविण शंखपाळ 
  
  //package wizard;
  
  import java.io.*;
  import java.math.*;
  import java.util.*;
  import java.text.*;
  
  public class Luna_Lovegood {
  
  	public static void main(String[] args) {
  
  //		try {
  
  		FastReader fr = new FastReader();
  		PrintWriter pt = new PrintWriter(System.out);
  
  		int t = fr.nextInt();
  
  		while (t > 0) {
  
  			int n = fr.nextInt(), odd = 0, even = 0;
  			long A[] = new long[n];
  
  			for (int i = 0; i < n; i++) {
  				A[i] = fr.nextLong();
  				if (A[i] % 2 == 0) {
  					even++;
  				} else {
  					odd++;
  				}
  			}
  
  			if (Math.abs(odd - even) <= 1) {
  
  				if (odd > even) {
  					long odd_ind = 0, even_ind = 1, ans = 0;
  
  					for (int i = 0; i < n; i++) {
  						if (A[i] % 2 == 0) {
  							ans += Math.abs(even_ind - i);
  							even_ind += 2;
  						} else {
  							ans += Math.abs(odd_ind - i);
  							odd_ind += 2;
  						}
  					}
  					pt.println(ans / 2);
  
  				} else if (even > odd) {
  
  					long odd_ind = 1, even_ind = 0, ans = 0;
  
  					for (int i = 0; i < n; i++) {
  						if (A[i] % 2 == 0) {
  							ans += Math.abs(even_ind - i);
  							even_ind += 2;
  						} else {
  							ans += Math.abs(odd_ind - i);
  							odd_ind += 2;
  						}
  					}
  					pt.println(ans / 2);
  				} else {
  
  					long odd_ind1 = 1, even_ind1 = 0, ans1 = 0, ans2 = 0, odd_ind2 = 0, even_ind2 = 1;
  
  					for (int i = 0; i < n; i++) {
  						if (A[i] % 2 == 0) {
  							ans1 += Math.abs(even_ind1 - i);
  							even_ind1 += 2;
  						} else {
  							ans1 += Math.abs(odd_ind1 - i);
  							odd_ind1 += 2;
  						}
  					}
  
  					for (int i = 0; i < n; i++) {
  						if (A[i] % 2 == 0) {
  							ans2 += Math.abs(even_ind2 - i);
  							even_ind2 += 2;
  						} else {
  							ans2 += Math.abs(odd_ind2 - i);
  							odd_ind2 += 2;
  						}
  					}
  
  					pt.println(Math.min(ans2, ans1) / 2);
  
  				}
  
  			} else {
  
  				pt.println(-1);
  
  			}
  
  			t--;
  		}
  		pt.close();
  
  //		} catch (
  //
  //		Exception e) {
  //			return;
  //		}
  	}
  
  	static int lower_bound(long[] arr, int begin, int end, long tar) {
  		while (begin < end) {
  			int mid = begin + (end - begin) / 2;
  			if (arr[mid] < tar)
  				begin = mid + 1;
  			else if (arr[mid] >= tar)
  				end = mid;
  		}
  		return begin;
  //		lower bound gives largest index of a number smaller than (if target is not present) or equal to target(if target is present) 
  //      for complete array use begin = 0 and end = n
  	}
  
  	static int upper_bound(long[] arr, int begin, int end, long tar) {
  		while (begin < end) {
  			int mid = begin + (end - begin) / 2;
  			if (arr[mid] <= tar)
  				begin = mid + 1;
  			else if (arr[mid] > tar)
  				end = mid;
  		}
  
  		return begin;
  //		upper bound gives smallest index of a number strictly greater than target
  //	    for complete array use begin = 0 and end = n
  	}
  
  	public static void mergeSort(String[] nameGo) {
  		if (nameGo.length > 1) {
  			String[] leftGo = new String[nameGo.length / 2];
  			String[] rightGo = new String[nameGo.length - nameGo.length / 2];
  			for (int so = 0; so < leftGo.length; so++) {
  				leftGo[so] = nameGo[so];
  			}
  			for (int ki = 0; ki < rightGo.length; ki++) {
  				rightGo[ki] = nameGo[ki + nameGo.length / 2];
  			}
  			mergeSort(leftGo);
  			mergeSort(rightGo);
  			merges(nameGo, leftGo, rightGo);
  		}
  	}
  
  	public static void merges(String[] nameH, String[] leftH, String[] rightH) {
  		int as = 0;
  		int bs = 0;
  		for (int i = 0; i < nameH.length; i++) {
  			if (bs >= rightH.length || (as < leftH.length && leftH[as].compareToIgnoreCase(rightH[bs]) < 0)) {
  				nameH[i] = leftH[as];
  				as++;
  			} else {
  				nameH[i] = rightH[bs];
  				bs++;
  			}
  		}
  	}
  
  	static void merge(long arr[], int l, int m, int r) {
  
  		int n1 = m - l + 1;
  		int n2 = r - m;
  
  		long L[] = new long[n1];
  		long R[] = new long[n2];
  
  		for (int i = 0; i < n1; ++i)
  			L[i] = arr[l + i];
  		for (int j = 0; j < n2; ++j)
  			R[j] = arr[m + 1 + j];
  
  		int i = 0, j = 0;
  
  		int k = l;
  		while (i < n1 && j < n2) {
  			if (L[i] <= R[j]) {
  				arr[k] = L[i];
  				i++;
  			} else {
  				arr[k] = R[j];
  				j++;
  			}
  			k++;
  		}
  
  		while (i < n1) {
  			arr[k] = L[i];
  			i++;
  			k++;
  		}
  
  		while (j < n2) {
  			arr[k] = R[j];
  			j++;
  			k++;
  		}
  	}
  
  	static void sort(long arr[], int l, int r) {
  		if (l < r) {
  
  			int m = l + (r - l) / 2;
  
  			sort(arr, l, m);
  			sort(arr, m + 1, r);
  
  			merge(arr, l, m, r);
  		}
  	}
  
  	static class Pair implements Comparable<Pair> {
  		int a, b;
  
  		Pair(int a, int b) {
  			this.a = a;
  			this.b = b;
  		}
  
  		public int compareTo(Pair o) {
  			// TODO Auto-generated method stub
  			if (this.a != o.a)
  				return Integer.compare(this.a, o.a);
  			else
  				return Integer.compare(this.b, o.b);
  			// return 0;
  		}
  
  		public boolean equals(Object o) {
  			if (o instanceof Pair) {
  				Pair p = (Pair) o;
  				return p.a == a && p.b == b;
  			}
  			return false;
  		}
  
  	}
  
  	static int binarySearch(int arr[], int first, int last, int key) {
  		int mid = (first + last) / 2;
  		while (first <= last) {
  			if (arr[mid] < key) {
  				first = mid + 1;
  			} else if (arr[mid] == key) {
  				return mid;
  			} else {
  				last = mid - 1;
  			}
  			mid = (first + last) / 2;
  		}
  		return -1;
  	}
  
  	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;
  		}
  	}
  }
  