#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
const int maxm = 1e6 + 10;
const long long mod = 1e9 + 7;
const int inf = 0x3ffffff;
const double eps = 1e-5;
int t;
string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> s;
    int dp[2];
    dp[0] = 0, dp[1] = 0;
    for (int i = 0; i < s.size(); i++) {
      int a = dp[0], b = dp[1];
      dp[0] = a + (s[i] == '1' ? 0 : 1);
      dp[1] = min(b, a) + (s[i] == '1' ? 1 : 0);
    }
    int dp1[2];
    dp1[0] = 0, dp1[1] = 0;
    for (int i = 0; i < s.size(); i++) {
      int a = dp1[0], b = dp1[1];
      dp1[0] = a + (s[i] == '0' ? 0 : 1);
      dp1[1] = min(b, a) + (s[i] == '0' ? 1 : 0);
    }
    cout << min(min(dp[0], dp[1]), min(dp1[0], dp1[1])) << endl;
  }
  return ~~(0 - 0);
}
