#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long double pi = acos(-1);
const long long maxn = 1e5 + 5;
const int mod = 1073741824;
const long long INF = 1e18;
const int MX = 2000000001;
vector<long long> v[1001];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long t, q, n, a, b, c, d, k = 0, l, m, r, x = 0, y = 0, z = 0, sum = 0,
                                 ans = 0, temp = 0, res = 0;
  cin >> t;
  while (t--) {
    string second;
    cin >> second;
    n = ans = (long long)(second).size();
    for (long long i = 0; i < (n); i++) {
      auto it = begin(second) + i;
      l = count(begin(second), it, '0');
      r = count(it + 1, end(second), '1');
      ans = min(ans, l + r);
      ans = min(ans, i - l + ((long long)(second).size() - i - 1 - r));
    }
    cout << ans << "\n";
  }
}
