#include <bits/stdc++.h>
using namespace std;
void solve(int cno) {
  long long i, j, l, k, n;
  string brr;
  cin >> brr;
  n = brr.size();
  long long arr[n];
  for (i = 0; i < n; i++) {
    arr[i] = (brr[i] - '0');
  }
  long long presum[n];
  presum[0] = arr[0];
  for (i = 1; i < n; i++) {
    if (arr[i] == 1)
      presum[i] = presum[i - 1] + 1;
    else
      presum[i] = presum[i - 1];
  }
  long long ans1 = 1000000007, ans2 = 1000000007;
  for (i = 0; i < n; i++) {
    long long temp1 = presum[i];
    long long temp2 = (n - i - 1) - (presum[n - 1] - presum[i]);
    ans1 = min(ans1, temp1 + temp2);
  }
  for (i = 0; i < n; i++) {
    long long temp1 = i + 1 - presum[i];
    long long temp2 = (presum[n - 1] - presum[i]);
    ans2 = min(ans2, temp1 + temp2);
  }
  cout << min(ans1, ans2) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int TESTS = 1;
  cin >> TESTS;
  long long i = 1;
  while (TESTS--) {
    solve(i);
    i++;
  }
  return 0;
}
