#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
int t, cnt[2][2][2000], len, ans;
string s;
void fun(int u, int x) {
  if (x)
    cnt[0][u][x] = cnt[0][u][x - 1];
  else
    cnt[0][u][x] = 0;
  if (s[x] - '0' != u) cnt[0][u][x]++;
}
void gun(int u, int x) {
  if (x < len - 1)
    cnt[1][u][x] = cnt[1][u][x + 1];
  else
    cnt[1][u][x] = 0;
  if (s[x] - '0' != u) cnt[1][u][x]++;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> s;
    len = s.length();
    ans = 2000;
    cnt[1][1][len] = 0;
    cnt[1][0][len] = 0;
    for (int i = 0; i < len; i++) {
      fun(0, i);
      fun(1, i);
    }
    for (int i = len - 1; i >= 0; i--) {
      gun(0, i);
      gun(1, i);
    }
    int cur = 0;
    cur = min(cnt[1][0][0], cnt[1][1][0]);
    ans = min(ans, cur);
    for (int i = 0; i < len; i++) {
      cur =
          min(cnt[0][0][i] + cnt[1][1][i + 1], cnt[0][1][i] + cnt[1][0][i + 1]);
      ans = min(ans, cur);
    }
    cout << ans << "\n";
  }
  return 0;
}
