#include <bits/stdc++.h>
using namespace std;
long long int c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, t, x, y, z;
long long int mn = 8675435789, mx = -8675868757, PI = 3.14159265359,
              md = 1000000007, aa = 0, bb = 0, cc = 0;
string r, s, u, v, w;
long long int a[250002], b[250002];
queue<long long int> qu, qe;
pair<long long int, long long int> pp[30030];
set<string> se, sa;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  }
  cin >> t;
  while (t--) {
    cin >> s;
    n = s.size();
    map<long long int, long long int> mp, mq;
    o = 0, e = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '1') {
        mp[i + 1]++;
        e++;
      } else {
        mq[i + 1]++;
        o++;
      }
      mp[i + 1] += mp[i];
      mq[i + 1] += mq[i];
    }
    p = min(e, o);
    for (i = 1; i < n + 1; i++) {
      c = e - mp[i] + mq[i];
      d = o - mq[i] + mp[i];
      x = min(c, d);
      p = min(p, x);
    }
    cout << p << endl;
  }
}
