#include <bits/stdc++.h>
using namespace std;
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
void solve() {
  string s;
  cin >> s;
  long long t0 = 0, t1 = 0;
  long long pre0[s.size()], pre1[s.size()];
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      t1++;
      pre0[i] = t0;
      pre1[i] = t1;
    } else {
      t0++;
      pre0[i] = t0;
      pre1[i] = t1;
    }
  }
  vector<long long> v;
  v.push_back(t0);
  v.push_back(t1);
  for (long long i = 0; i < s.size(); i++) {
    long long a = 0;
    a += pre1[i];
    a += t0 - pre0[i];
    v.push_back(a);
    a = 0;
    a += pre0[i];
    a += t1 - pre1[i];
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  cout << v[0] << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
