#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
void setIO(string name = "1363B") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    int n = str.length();
    int oc = 0, zc = 0;
    for (int i = 0; i < n; i++) {
      if (str[i] == '1') {
        oc++;
      } else {
        zc++;
      }
    }
    int co = 0, cz = 0;
    int minV = n;
    for (int i = 0; i < n; i++) {
      if (str[i] == '1') {
        co++;
      } else {
        cz++;
      }
      minV = min(minV, min(co + zc - cz, cz + oc - co));
    }
    cout << minV << "\n";
  }
}
