void main() {
  problem();
}

enum BIN2HEX = [
  "0000": '0', "0001": '1', "0010": '2', "0011": '3',
  "0100": '4', "0101": '5', "0110": '6', "0111": '7',
  "1000": '8', "1001": '9', "1010": 'A', "1011": 'B',
  "1100": 'C', "1101": 'D', "1110": 'E', "1111": 'F'
];

string binToHex(string binStr) {
  string bin = "0000"[0..4 - (binStr.length % 4)] ~ binStr;
  char[] hex = new char[bin.length / 4];
  for(int i = 0; i < bin.length; i += 4) {
    hex[i/4] = BIN2HEX[bin[i..i + 4]];
  }

  return "0x" ~ cast(string)hex;
}

void problem() {

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

    int mod;
    {
      BigInt q, r;
      x.divMod(BigInt(popcount), q, r);
      mod = r.toInt;
    }

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

    return ans;
  }

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

  void solve() {
    const basePopCount = cast(int)X.count('1');
    const BigInt base = binToHex(X);

    BigInt delta = 1 << N;
    foreach(i; 0..N) {
      const deltaPlus = X[i] == '0';
      const popCount = basePopCount + (deltaPlus ? -1 : 1);
      auto x = base + (deltaPlus ? delta : -delta);
      calc(x, popCount).writeln;

      delta >>= 1;
    }
  }

  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;

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