#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int ans = 1024;
  int n = s.size();
  int tmp = 0;
  for (int i = 0; i < n; ++i)
    if (s[i] == '0') tmp++;
  ans = min(ans, tmp);
  tmp = 0;
  for (int i = 0; i < n; ++i)
    if (s[i] == '1') tmp++;
  ans = min(ans, tmp);
  for (int i = 0; i < n; ++i) {
    if (s[i] == '1') {
      int tmp1 = 0, tmp2 = 0;
      for (int j = 0; j < i; ++j)
        if (s[j] == '0')
          tmp1++;
        else
          tmp2++;
      for (int j = i + 1; j < n; ++j)
        if (s[j] == '0')
          tmp2++;
        else
          tmp1++;
      ans = min(ans, min(tmp1, tmp2));
    }
  }
  cout << (ans == 1024 ? 0 : ans) << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
