#include <iostream>
using namespace std;

template<typename T>
T power(T x, long long k, long long mod){
  T ret{1};
  while(k > 0){
    if(k&1) ret *= x, ret %= mod;
    x *= x, x %= mod;
    k /= 2;
  }
  return ret;
}

int main(){
  int N;
  string X;
  cin >> N >> X;
  int p = 0;
  for(int i = 0; i < N; ++i){
    p += (X[i] -'0');
  }
  
  auto f = [](int x){
             int ret = 0;
             while(x > 0){
               ++ret;
               x %= __builtin_popcount(x);
             }
             return ret;
           };

  int l = 0, m = 0, r = 0;
  for(int i = 0; i < N; ++i){

    m *= 2, r *= 2;
    int d = X[i] - '0';
    m += d, r += d;
    m %= p, r %= p+1;
    if(p > 1){
      l *= 2;
      l += d;
      l %= p-1;
    }
  }

  for(int i = 0; i < N; ++i){
    if(X[i] == '0'){
      int t = (r + power<long long>(2,N-i-1,p+1))%(p+1);
      cout << 1+f(t) << '\n';
    }else{
      if(p == 1){
        cout << 0 << '\n';
        continue;
      }
      int t = (l - power<long long>(2,N-i-1,p-1))%(p-1);
      t = (t+p-1)%(p-1);
      cout << 1+f(t) << endl;
    }
  }
}
