#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string a;
    cin >> a;
    int ans = 0;
    int out = INT_MAX;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == '0') {
        int temp = 0;
        for (int j = i + 1; j < a.size(); j++)
          if (a[j] == '1') temp++;
        for (int j = 0; j < i; j++)
          if (a[j] == '0') temp++;
        out = min(out, temp);
      } else {
        int temp = 0;
        for (int j = i + 1; j < a.size(); j++)
          if (a[j] == '0') temp++;
        for (int j = 0; j < i; j++)
          if (a[j] == '1') temp++;
        out = min(out, temp);
      }
    }
    cout << out << endl;
  }
}
