#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long len, x, y, mini, one = 0, zero = 0, dOne = 0, dZero = 0;
    len = s.length();
    for (long long i = 0; i < len; i++)
      if (s[i] == '1')
        one++;
      else
        zero++;
    mini = min(one, zero);
    for (long long i = 0; i < len; i++) {
      if (s[i] == '0')
        dZero++;
      else
        dOne++;
      mini = min(mini, dZero + (one - dOne));
      mini = min(mini, dOne + (zero - dZero));
    }
    cout << (mini) << endl;
  }
}
