#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

template<class T>
T fastpower(T a, long long n, ll modu) {  // n must be >= 1
  if (n==0) {return (1%modu);}
  if (n % 2 == 0) {  
      T halfpower = fastpower<T>(a, n/2, modu);
      return (halfpower*halfpower) % modu;
  } else {
      if (n == 1) {  return a; } else {  
          T halfpower = fastpower<T>(a, n/2, modu);
          return (((halfpower*halfpower) % modu)*a)%modu;
      }
  }
};

int solve(int rr) {
    if (rr==0) {return 0;}
    int ct = 0;
    int rr_orig(rr);
    while (rr>0) {
        ct += rr%2;
        rr/=2;
    }
    return 1+solve(rr_orig%ct);
}

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        readstring(s);

        ll ones_count = count(s.begin(), s.end(), '1');
        ll remplusone = 0, remminusone = 0;
        forr(i,0,s.size()) {
            if (s[i]=='1') {
              remplusone += fastpower<ll>(2, s.size()-i-1, ones_count+1);
              remplusone = remplusone % (ones_count+1);
            }
        }
        if (ones_count-1>0) {
          forr(i,0,s.size()) {
            if (s[i]=='1') {
              remminusone += fastpower<ll>(2, s.size()-i-1, ones_count-1);
              remminusone = remminusone % (ones_count-1);
            }
          }
        }

        for(int i = 0; i<s.size(); ++i) {
            int real_count;
            if (s[i]=='0') {
                real_count = ones_count+1;
            } else {
                real_count = ones_count-1;
            }
            if (real_count==0) {
                cout << 0 << endl; continue;
            }
            int result = 0;
            if (real_count==ones_count+1) {
                result = remplusone;
                result += fastpower<ll>(2, s.size()-i-1, ones_count+1);
                result = result % real_count;
            } else {
                result = remminusone;
                result += real_count - fastpower<ll>(2, s.size()-i-1, ones_count-1);
                result = result % real_count;
            }
            cout << 1+solve(result) << endl;
            
        }

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}


Measured memory_bytes: 3780