void main() {
  problem();
}

int mod(string x, int d) {
  int r;
  auto xs = x.length;
  foreach(i; 0..xs) {
    r = (r * 2 + (x[i] - '0')) % d;
  }

  return r;
}

int mod(BigInt b, int popcount) {
  BigInt q, r;
  b.divMod(BigInt(popcount), q, r);
  return r.toInt;
}

void problem() {
  int calc(BigInt x, int popcount) {
    if (x == 0) return 0;

    int m = x.mod(popcount);
    int ans = 1;
    while(m > 0) {
      ans++;
      m %= m.popcnt;
    }

    return ans;
  }

  auto N = scan!int;
  auto X = scan;

  void solve() {
    const basePopCount = cast(int)X.count('1');
    const baseFirstModPlus = X.mod(basePopCount + 1);
    const baseFirstModMinus = basePopCount == 1 ? 0 : X.mod(basePopCount - 1);

    foreach(i; 0..N) {
      const deltaPlus = X[i] == '0';
      const popCount = basePopCount + (deltaPlus ? 1 : -1);
      if (popCount == 0) {
        writeln(0);
        continue;
      }

      int firstMod;
      auto deltaMod = powmod(2U, (N - i - 1).unsigned, popCount.unsigned);
      if (deltaPlus) {
        firstMod = (baseFirstModPlus + deltaMod) % popCount;
      } else {
        firstMod = baseFirstModMinus - deltaMod;
        firstMod = firstMod < 0 ? popCount + firstMod : firstMod;
      }

      int ans = 1;
      while(firstMod > 0) {
        ans++;
        firstMod %= firstMod.popcnt;
      }
      ans.writeln;
    }
  }

  solve();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Queue = Tuple!(long, "from", long, "to");
import std.bigint, std.functional, core.bitop;

// -----------------------------------------------
