#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int t;
string s;
int dp[N][2];
char x;
int solve(int i, int flag) {
  if (i == s.size()) return 0;
  if (dp[i][flag] != -1) return dp[i][flag];
  int ret = 0;
  if (flag == 0) {
    if (s[i] == x) {
      ret = solve(i + 1, 0);
    } else {
      ret = min(solve(i + 1, 1), solve(i + 1, 0) + 1);
    }
  } else {
    if (s[i] == x) {
      ret = solve(i + 1, 1) + 1;
    } else {
      ret = solve(i + 1, 1);
    }
  }
  return dp[i][flag] = ret;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  ;
  cin >> t;
  while (t--) {
    cin >> s;
    x = '0';
    memset(dp, -1, sizeof dp);
    int ans = solve(0, 0);
    x = '1';
    memset(dp, -1, sizeof dp);
    ans = min(ans, solve(0, 0));
    cout << ans << endl;
  }
  return 0;
}
