#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  long long int n = s.size();
  vector<long long int> zero, one;
  zero.push_back(0);
  one.push_back(0);
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      zero.push_back(zero[i] + 1);
      one.push_back(one[i]);
    } else {
      zero.push_back(zero[i]);
      one.push_back(one[i] + 1);
    }
  }
  long long int ans = min(n - zero[n], n - one[n]);
  for (int i = 1; i < n + 1; i++) {
    ans = min(ans, abs(i - zero[i]) + abs(n - i - one[n] + one[i]));
    ans = min(ans, abs(i - one[i]) + abs(n - i - zero[n] + zero[i]));
  }
  cout << ans << endl;
  return;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
}
