#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const vector<long long int> dx = {1, -1, 0, 0};
const vector<long long int> dy = {0, 0, 1, -1};
void solve() {
  string s;
  cin >> s;
  long long int k = s.length();
  long long int cnt = 1;
  char cur = s[0];
  long long int zer = 0;
  if (s[0] == '0') zer++;
  long long int one = 0;
  long long int prefix[1010];
  prefix[0] = zer;
  for (long long int i = 1; i < k; i++) {
    if (cur != s[i]) {
      cnt++;
      cur = s[i];
    }
    if (s[i] == '0') {
      zer++;
    }
    prefix[i] = zer;
  }
  one = k - zer;
  long long int least = min(zer, one);
  for (long long int i = 0; i < k; i++) {
    least = min(least, i + 1 - prefix[i] + (zer - prefix[i]));
    least = min(least, prefix[i] + one - (i + 1 - prefix[i]));
  }
  cout << least << "\n";
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
