#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
pair<int, int> l[N];
pair<int, int> *a = l + 1;
int main() {
  int te;
  cin >> te;
  while (te--) {
    string s;
    cin >> s;
    int t0 = 0, t1 = 0;
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (i == 0) {
        if (s[i] == '1') {
          a[i].second = 1;
          t1++;
          a[i].first = 0;
          continue;
        }
        a[i].second = 0;
        a[i].first = 1;
        t0++;
        continue;
      }
      if (s[i] == '1') {
        a[i].second = a[i - 1].second + 1;
        a[i].first = a[i - 1].first;
        t1++;
        continue;
      }
      a[i].first = a[i - 1].first + 1;
      a[i].second = a[i - 1].second;
      t0++;
    }
    int mn = n + 1;
    for (int i = -1; i < n; i++) {
      int g = 0;
      g += a[i].second;
      g += t0 - a[i].first;
      mn = min(mn, g);
    }
    for (int i = -1; i < n; i++) {
      int g = 0;
      g += a[i].first;
      g += t1 - a[i].second;
      mn = min(mn, g);
    }
    cout << mn << endl;
  }
}
