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.util.*;
import java.io.*;

public class Solution {
	int solve(String s) {
		int zero = 0, one = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == '1')
				one++;
			else
				zero++;
		}

		int min = Math.min(zero, one), cOne = 0, cZero = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == '1')
				cOne++;
			else
				cZero++;

			min = Math.min(min, cZero + one - cOne);
			min = Math.min(min, cOne + zero - cZero);
		}

		return min;
	}
	public static void main(String[] args) throws IOException {
		for(int t = io.nextInt(); t-- > 0;) {
			io.println(new Solution().solve(io.nextString()));
		}

		io.close();
	}

	static IO io = new IO();
	static class IO {
		private byte[] buf;
		private InputStream in;
		private PrintWriter pw;
		private int total, index;

		public IO() {
			buf = new byte[1024];
			in = System.in;
			pw = new PrintWriter(System.out);
		}

		public int next() throws IOException {
			if(total < 0) 
				throw new InputMismatchException();
			if(index >= total) {
				index = 0;
				total = in.read(buf);
				if(total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public int nextInt() throws IOException {
			int n = next(), integer = 0;
			while(isWhiteSpace(n))
				n = next();
			int neg = 1;
			if(n == '-') {
				neg = -1;
				n = next();
			}
			while(!isWhiteSpace(n)) {
				if(n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = next();
				}
				else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] arr = new int[n];
			for(int i = 0; i < n; i++) 
				arr[i] = nextInt();
			return arr;
		}

		public long nextLong() throws IOException {
			long integer = 0l;
			int n = next();
			while(isWhiteSpace(n))
				n = next();
			int neg = 1;
			if(n == '-') {
				neg = -1;
				n = next();
			}
			while(!isWhiteSpace(n)) {
				if(n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = next();
				}
				else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double nextDouble() throws IOException {
			double doub = 0;
			int n = next();
			while(isWhiteSpace(n))
				n = next();
			int neg = 1;
			if(n == '-') {
				neg = -1;
				n = next();
			}
			while(!isWhiteSpace(n) && n != '.') {
				if(n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = next();
				}
				else
					throw new InputMismatchException();
			}
			if(n == '.') {
				n = next();
				double temp = 1;
				while(!isWhiteSpace(n)) {
					if(n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = next();
					}
					else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String nextString() throws IOException {
			StringBuilder sb = new StringBuilder();
			int n = next();
			while(isWhiteSpace(n)) 
				n = next();
			while(!isWhiteSpace(n)) {
				sb.append((char)n);
				n = next();
			}
			return sb.toString();
		}

		public String nextLine() throws IOException {
			int n = next();
			while(isWhiteSpace(n))
				n = next();
			StringBuilder sb = new StringBuilder();
			while(!isEndOfLine(n)) {
				sb.append((char)n);
				n = next();
			}
			return sb.toString();
		}

		private boolean isWhiteSpace(int n) {
			return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1;
		}

		private boolean isEndOfLine(int n) {
			return n == '\n' || n == '\r' || n == -1;
		}

		public void print(Object obj) {
			pw.print(obj);
		}

		public void println(Object... obj) {
			if(obj.length == 1)
				pw.println(obj[0]);
			else {
				for(Object o: obj)
					pw.print(o + " ");
				pw.println();
			}
		}

		public void close() throws IOException {
			pw.close();
		}
	}
}
