#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int ans = 0;
    int x = 0;
    int y = 0;
    int n = s.size();
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '0') {
        x++;
      } else {
        y++;
      }
    }
    ans = min(x, y);
    vector<int> p;
    vector<int> m;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0') {
        p.push_back(0);
      } else {
        m.push_back(1);
      }
      int f = p.size() + y - m.size();
      ans = min(ans, f);
      int e = m.size() + x - p.size();
      ans = min(ans, e);
    }
    cout << ans << endl;
  }
  return 0;
}
