#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long t1 = 0, t0 = 0, c1 = 0, c0 = 0;
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == '1')
        t1++;
      else
        t0++;
    }
    long long cost1 = 0, cost0 = 0, cost = INT_MAX, costt = 0;
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == '1')
        c1++;
      else
        c0++;
      cost0 = c0 + t1 - c1;
      cost1 = c1 + t0 - c0;
      costt = min(cost0, cost1);
      cost = min(cost, costt);
    }
    cost = min(cost, t1);
    cost = min(cost, t0);
    cout << cost << endl;
  }
}
