#include <bits/stdc++.h>
using namespace std;
long long i, j;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    int on = 0, z = 0, pz = 0, pon = 0;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1')
        on++;
      else
        z++;
    }
    int ans = min(on, z);
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '0') {
        pz++;
        z--;
      } else {
        pon++;
        on--;
      }
      ans = min(ans, pon + z);
      ans = min(ans, pz + on);
    }
    cout << ans << endl;
  }
}
