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.math.BigInteger;
													import java.sql.Array;
												    import java.util.ArrayList;
													import java.util.Arrays;
													import java.util.Collection;
													import java.util.Collections;
													import java.util.Comparator;
		import java.util.Deque;
		import java.util.HashMap;
				import java.util.HashSet;
				import java.util.InputMismatchException;
		import java.util.LinkedList;
		import java.util.PriorityQueue;
		import java.util.Queue;
		import java.util.Scanner;
															import java.util.Set;
															import java.util.Stack;
													import java.io.BufferedReader;
													import java.io.IOException;
													import java.io.InputStream;
													import java.io.InputStreamReader;
													import java.util.Scanner;
													import java.util.StringTokenizer;
													import java.util.TreeMap;
													import java.util.TreeSet;
												
													
													
													
													
													
													public class Main {
									
														
													static long dp[][];
														public static void main(String[] args) {
														StringBuilder ans=new StringBuilder();
														FastReader sc=new FastReader();
														int t=sc.nextInt();
														
														
														while(t-->0) {
														StringBuilder s=new StringBuilder(sc.next());
														
														ArrayList<Long>A=new ArrayList<>();
														
														int n=s.length();
														for(int i=0;i<n;i++) {
															
															long count=1;
															
															if(i!=n-1&&s.charAt(i)==s.charAt(i+1)) {
																
																while(i<n-1&&s.charAt(i+1)==s.charAt(i))
																{	i++;
																count++;
																}
																
															
															}
															A.add(count);
															
															
														}
														//System.out.println(A);
														
														
														if(A.size()<=2) {
															
															System.out.println(0);
														continue;
														}
														
														
														dp=new long[A.size()+1][2];
														
														for(int i=0;i<A.size()+1;i++)
															{
															dp[i][0]=-1;
																	dp[i][1]=-1;
																			
															}
														

														long a=solve(A,0,A.size());
														
														for(int i=0;i<A.size()+1;i++)
															{
															dp[i][0]=-1;
																	dp[i][1]=-1;
																			
															}
														

														long b=solve(A,0,A.size()-1);
														System.out.println(Math.min(a,b));
														
														}
														
												
														
														
														
														
														
													}
														
														
														
												static long solve(ArrayList<Long>A,int turn,int n) {
													//if(n<0)return Integer.MAX_VALUE;
													if(n<=0)return 0;
													
													if(dp[n][turn]!=-1)return dp[n][turn];
													
													if(turn==0) {
														
														return dp[n][turn]=Math.min(A.get(n-1)+solve(A,turn,n-2),solve(A,1,n-1));
														
													}
													
													else return dp[n][turn]= A.get(n-1)+solve(A,turn ,n-2);
													
												}
														
														
													static class Helper{
														
														int val;int ind;
														
														Helper(int val,int ind){
															this.val=val;
															this.ind=ind;
														}
													}
														
														
														
														
														
														
														//	System.out.println(max);
												
														
													
														
													
											
						//System.out.println(ans.toString());
						//main(						
													
									
							
						static void solvedfs(ArrayList<ArrayList<Integer>>adj,int n,int v,int subt[],int subtAns[],boolean []visited) {
									
									
									int count=1;
									int ans=0;
									visited[v]=true;
									for(int u:adj.get(v)) {
										
										
										if(!visited[u])
										{
											//System.out.println(v+" "+subt[v]+" "+n);
											subtAns[u]=Math.max(subtAns[u], subt[v]-subtAns[u]);
											
										solvedfs(adj, n, u, subt, subtAns, visited);			
										
										}
									}
									
								
									
									
									
									
									
								}
								
														
														
														
										static int dfs(ArrayList<ArrayList<Integer>>adj,int v,int subt[],int subtAns[],boolean []visited) {
										
											
											int count=0;
											int ans=0;
											visited[v]=true;
											for(int u:adj.get(v)) {
												
												
												if(!visited[u])
												{
													count+=ans;
													ans=Math.max(dfs(adj,u,subt,subtAns,visited),ans);
												}
											}
												subt[v]=count;
												subtAns[v]=ans;
												return ans+1;
												
											
											
											
											
											
										}
														
										
														
														
										static	int solve(ArrayList<ArrayList<Integer>>adj,int node,ArrayList<Integer>A)			
											{
												if(adj.get(node).size()==0)return 1;
												
												int count=0;
												for(int v:adj.get(node)) {
													
													count+=solve(adj,v,A);
													
												}
												
												A.set(node,count);
												return count+1;
												
												
												
											}
														
														
														
														
														
														
														
											static void dfs(String[]building,int i,int j,int n,int m, boolean visited[][]) {
												
												
												visited[i][j]=true;
												
												if(isValid(building,i+1,j,n,m,visited))
												{	visited[i+1][j]=true;
													dfs(building,i+1,j,n,m,visited);
												
												}
													if(isValid(building,i-1,j,n,m,visited))
												{
													visited[i-1][j]=true;
													dfs(building,i-1,j,n,m,visited);
												}
												 if(isValid(building,i,j+1,n,m,visited))
												{visited[i][j+1]=true;
													dfs(building,i,j+1,n,m,visited);
												}
														if(isValid(building,i,j-1,n,m,visited))
												{visited[i][j-1]=true;
													dfs(building,i,j-1,n,m,visited);
												}
												
												
												
												
											}
											static boolean isValid(String[]building,int i,int j,int n,int m, boolean visited[][])		
											{
												if(i==-1||j==-1||i==n||j==m||visited[i][j]||building[i].charAt(j)=='#')
													return false;
											return true;
											}
														
														
														
														
										static	void compute(boolean sieve[],int n) {
												
												for(int i=2;i<=n;i++) {
													if(sieve[i])continue;
													
													for(int j=2*i;j<n;j+=i)
													{
														sieve[j]=true;
													}
													
												}
													
												
												
											}
										
										static	void computeHs(boolean sieve[]) {
											int n=(int)(1e9-1e7+1);
											for(int i=1;i<n;i++) {
												if(sieve[i])continue;
												
												for(int j=2*i;j<n;j+=i)
												{
													sieve[j]=true;
												}
												
											}
											
										}
									
										
											
														
														
														static boolean isValid(StringBuilder s,int w) {
															if(w>s.length())return false;
															HashSet<Character>hs=new HashSet<Character>();
															int a[]=new int[3];
															
															for(int i=0;i<w;i++) {
															
																++a[s.charAt(i)-49];
																
															}
															
															if(a[0]>0&&a[1]>0&&a[2]>0)return true;
														
															int start=0;
															int end=w;
															
															while(end!=s.length()) {
																--a[s.charAt(start)-49];
																
																	++a[s.charAt(end)-49];
																
																			start++;
																				end++;
																				if(a[0]>0&&a[1]>0&&a[2]>0)return true;
																						
															}
															return false;
															
															
															
														}
										
														
														
														
											
									
														
											static int find(int parent[],int i) {
												
												if(parent[i]==-1)return i;
												
												return parent[i]=find(parent,parent[i]);
												
											}
											static void union(int parent[],int rank[],int s1,int s2) {
												
												if(rank[s1]>=rank[s2]) {
													
													parent[s2]=s1;
													rank[s1]+=rank[s2];
												}
												
												else {
													
													parent[s1]=s2;
													rank[s2]+=rank[s1];
												}
												
												
											}
														
														
														
														
														
														
														
														
														
														
														
											static	int solve(String S,int K) {
													
													if(K<=0)return 0;
													if(S.charAt(K-1)!=S.charAt(K))
													return 1+solve(S,K-1);
													else return solve(S,K-1);
												}
												
												
												
												
						
						
							
						static	boolean isValid(int g[][],int r,int c,int n,int m,boolean visited[][],int s) {
								if(r==-1||r==n||c==-1||c==m||visited[r][c]||g[r][c]!=s)return false;
								return true;
							}
						
												
													
																							
													
											    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;
											        }
											    }
											 
												
													}
													
													
													
													
													    