#include <bits/stdc++.h>
using namespace std;
int PS[1001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ((void)0);
  ((void)0);
  ((void)0);
  int T, N;
  string s;
  for (cin >> T; T--;) {
    int ans = 0x3fffffff;
    cin >> s;
    N = s.size();
    for (int i = 0; i < N; i++) PS[i + 1] = PS[i] + s[i] - '0';
    for (int i = 0; i <= N; i++) {
      ans = min(ans, PS[i] + N - i - (PS[N] - PS[i]));
      ans = min(ans, i - PS[i] + PS[N] - PS[i]);
    }
    cout << ans << '\n';
  }
  return 0;
}
