Shubham has a binary string s. A binary string is a string containing only characters "0" and "1".

He can perform the following operation on the string any amount of times: 

  * Select an index of the string, and flip the character at that index. This means, if the character was "0", it becomes "1", and vice versa. 



A string is called good if it does not contain "010" or "101" as a subsequence — for instance, "1001" contains "101" as a subsequence, hence it is not a good string, while "1000" doesn't contain neither "010" nor "101" as subsequences, so it is a good string.

What is the minimum number of operations he will have to perform, so that the string becomes good? It can be shown that with these operations we can make any string good.

A string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters.

Input

The first line of the input contains a single integer t (1≤ t ≤ 100) — the number of test cases.

Each of the next t lines contains a binary string s (1 ≤ |s| ≤ 1000).

Output

For every string, output the minimum number of operations required to make it good.

Example

Input


7
001
100
101
010
0
1
001100


Output


0
0
1
1
0
0
2

Note

In test cases 1, 2, 5, 6 no operations are required since they are already good strings.

For the 3rd test case: "001" can be achieved by flipping the first character — and is one of the possible ways to get a good string.

For the 4th test case: "000" can be achieved by flipping the second character — and is one of the possible ways to get a good string.

For the 7th test case: "000000" can be achieved by flipping the third and fourth characters — and is one of the possible ways to get a good string.
import java.io.*;
import java.util.*;
import javafx.util.*;
public class abc {
	
	static int[][] graph;
	static int[] ans;

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		InputReader s = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);
		/*int w=s.nextInt();
		
		
		while(w-->0) {
			int n=s.nextInt();
			int x=s.nextInt();
			int[] arr=new int[n];
			boolean o=false,e=false;
			int odd=0,even=0;
			for(int i=0 ; i<arr.length ; i++) {
				arr[i]=s.nextInt();
				if(arr[i]%2==0) {
					even++;
				}else {
					odd++;
				}
			}
			if(n<x) {
				System.out.println("No");
				continue;
			}
			
			if(x%2==0) {
				while(x>1 && even>=0) {
					x--;
				}
				int count=0;
				while(x>=0 && odd>=0) {
					x--;
					count++;
				}
				if(x!=0 || count%2==0) {
					System.out.println("No");
				}else {
					System.out.println("Yes");
				}
			}else {
				while(x>1 && even>=0) {
					x--;
				}
				int count=0;
				while(x>=0 && odd>=0) {
					x--;
					count++;
				}
				if(x!=0 || count%2==0) {
					System.out.println("No");
				}else {
					System.out.println("Yes");
				}
			}
			
			
			if(x%2==0) {
				if(odd>=1 && even>=1 && odd+even>=x) {
					System.out.println("Yes");
				}else {
					System.out.println("No");
				}
			}else {
				if(odd>=1 && n>=x) {
					System.out.println("Yes");
				}else {
					System.out.println("No");
				}
			}
		*/	
		
		int w=s.nextInt();
		while(w-->0) {
			int ans=Integer.MAX_VALUE;
			String str=s.nextLine();
			for(int i=0 ; i<str.length() ; i++) {
				int left=0,right=0;
				int j=0,k=str.length()-1;
				while(j<i) {
					if(str.charAt(j)=='1') {
						left++;
					}
					j++;
				}
				while(k>=i) {
					if(str.charAt(k)=='0') {
						right++;
					}
					k--;
				}
				ans=Math.min(ans, right+left);
			}
			for(int i=0 ; i<str.length() ; i++) {
				int left=0,right=0;
				int j=0,k=str.length()-1;
				while(j<i) {
					if(str.charAt(j)=='0') {
						left++;
					}
					j++;
				}
				while(k>=i) {
					if(str.charAt(k)=='1') {
						right++;
					}
					k--;
				}
				ans=Math.min(ans, right+left);
			}
			System.out.println(ans);
		}
		
	}
	
	public static void dfs(char[][] arr , boolean[][] vis , int x , int y) {
		if(vis[x][y]) return;
		vis[x][y]=true;
		if(x-1>=0 && y>=0 && x-1<arr.length && y<arr[0].length && !vis[x-1][y] && arr[x-1][y]=='1') {
			dfs(arr,vis,x-1,y);
		}
		if(x>=0 && y-1>=0 && x<arr.length && y-1<arr[0].length && !vis[x][y-1] && arr[x][y-1]=='1') {
			dfs(arr,vis,x,y-1);
		}
	}
	
	public static ArrayList divisors(long n , long k) {
		ArrayList<Long> div = new ArrayList<>();
 
		for (long i = 1; i <= Math.sqrt(n); i++) {
			if (n % i == 0) {
				if(i<=k) {
					div.add(i);
				}
				
 
				if (n / i != i && n/i<=k)
					div.add(n / i);
			}
		}
		return div;
	}
	

	public static class Pair implements Comparable<Pair>{
		int l;
		int r;
		public Pair(int a , int b) {
			l=a;
			r=b;
		}
		public int compareTo(Pair p) {
			int d1=this.r-this.l;
			int d2=p.r-p.l;
			if(d1==d2) {
				return this.l-p.l;
			}else {
				return d2-d1;
			}
		}
	}
	
	static long power(long x, long y) 
    { 
		long temp=0l; 
        if( y == 0) 
            return 1l; 
        temp = power(x, y/2);  
          
        if (y%2 == 0) 
            return temp*temp; 
        else
        { 
            if(y > 0) 
                return x * temp * temp; 
            else
                return (temp * temp) / x; 
        } 
    }  
	
	
	public static boolean helper(int[] arr1 , int[] arr2) {
		boolean[] temp=new boolean[3];
		if(arr1.length==0) return true;
		if(arr1[0]!=arr2[0]) return false;
		temp[arr1[0]+1]=true;
		for(int i=1 ; i<arr1.length ; i++) {
			
			if(arr1[i]==arr2[i]) {
				
			}else if(arr1[i]<arr2[i]) {
				if(!temp[2]) {
					return false;
				}
			}else {
				if(!temp[0]) {
					return false;
				}
			}
			temp[arr1[i]+1]=true;
		}
		return true;
	}
	

	public static ArrayList Divisors(long n) {
		ArrayList<Long> div = new ArrayList<>();
 
		for (long i = 1; i <= Math.sqrt(n); i++) {
			if (n % i == 0) {
				div.add(i);
 
				if (n / i != i)
					div.add(n / i);
			}
		}
		return div;
	}
 
	public static int BinarySearch(long[] a, long k) {
		int n = a.length;
		int i = 0, j = n - 1;
		int mid = 0;
 
		if (k < a[0])
			return 0;
		else if (k >= a[n - 1])
			return n;
		else {
			while (j - i > 1) {
				mid = (i + j) / 2;
 
				if (k >= a[mid])
					i = mid;
				else
					j = mid;
			}
		}
 
		return i + 1;
	}
 
	public static long GCD(long a, long b) {
		if (b == 0)
			return a;
		else
			return GCD(b, a % b);
	}
 
	public static long LCM(long a, long b) {
		return (a * b) / GCD(a, b);
	}
 
	static class InputReader {
 
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;
 
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
 
		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		static class pair implements Comparable<pair> {
			Integer x, y;
 
			pair(int x, int y) {
				this.x = x;
				this.y = y;
			}
 
			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if (result == 0)
					result = y.compareTo(o.y);
 
				return result;
			}
 
			public String toString() {
				return x + " " + y;
			}
 
			public boolean equals(Object o) {
				if (o instanceof pair) {
					pair p = (pair) o;
					return p.x - x == 0 && p.y - y == 0;
				}
				return false;
			}
 
			public int hashCode() {
				return new Long(x).hashCode() * 31 + new Long(y).hashCode();
			}
		}
 
		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}
 
		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
 
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
 
	static class CodeX {
		public static void sort(long arr[]) {
			merge_sort(arr, 0, arr.length - 1);
		}
 
		private static void merge_sort(long A[], long start, long end) {
			if (start < end) {
				long mid = (start + end) / 2;
				merge_sort(A, start, mid);
				merge_sort(A, mid + 1, end);
				merge(A, start, mid, end);
			}
 
		}
 
		private static void merge(long A[], long start, long mid, long end) {
			long p = start, q = mid + 1;
			long Arr[] = new long[(int) (end - start + 1)];
			long k = 0;
 
			for (int i = (int) start; i <= end; i++) {
				if (p > mid)
					Arr[(int) k++] = A[(int) q++];
 
				else if (q > end)
					Arr[(int) k++] = A[(int) p++];
 
				else if (A[(int) p] < A[(int) q])
					Arr[(int) k++] = A[(int) p++];
 
				else
					Arr[(int) k++] = A[(int) q++];
			}
			for (int i = 0; i < k; i++) {
				A[(int) start++] = Arr[i];
			}
 
		}
 
	}
 
}


