// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

constexpr int Nbit= 200'000;

constexpr int sNbit= 21;



int nextX(const bitset<sNbit> &bsX, int popX){

  bitset<sNbit> X= bsX;



  int mod= 0;

  int base_mod= 1;

  while(X.count() > 0){

    if(X.test(0)){

      mod= (mod+ base_mod) % popX;

    }



    base_mod= (2* base_mod) % popX;

    X >>= 1;

  }



  return mod;

}



int init(const bitset<Nbit> &bsX, vector<int> *base_mod, int div){

  if(div==0){ return 0; }

  else{

    const size_t N= (int)base_mod->size();



    bitset<Nbit> X= bsX;

    int mod= 0;

    base_mod->at(0)= 1 % div;

    for(size_t i=0; i<N; i++){

      if(X.test(0)){

        mod= (mod+ base_mod->at(i)) % div;

      }



      if(i+1 < N){

        base_mod->at(i+1)= (2* base_mod->at(i)) % div;

      }

      X >>= 1;

    }



    return mod;

  }

}



int main(){

  int N;

  string X;

  cin >> N >> X;



  const bitset<Nbit> bsX(X);

  const int popX= (int)bsX.count();



  vector<int> offset_plus1(N);

  vector<int> offset_minus1(N);



  const int mod_popXplus1 = init(bsX, &offset_plus1 , popX+ 1);

  const int mod_popXminus1= init(bsX, &offset_minus1, popX- 1);

  

  for(int i=1; i<=N; i++){

    int bit_i= (bsX.test(N-i)) ? 0

                               : 1;

    int popXi= (bit_i==1) ? popX+ 1

                          : popX- 1;



    bitset<sNbit> bsXi;

    int ans_i= 0;

    while(popXi > 0){

      ans_i++;

      if(ans_i==1){

        int next= (bit_i==1) ? (mod_popXplus1+ offset_plus1.at(N-i)) % popXi

                             : (((mod_popXminus1- offset_minus1.at(N-i)) % popXi)+ popXi) % popXi;

        bsXi= bitset<sNbit>(next);

        popXi= (int)bsXi.count();

      }

      else{

        int next= nextX(bsXi, popXi);



        bsXi= bitset<sNbit>(next);

        popXi= (int)bsXi.count();

      }

    }



    cout << ans_i << endl;

  }

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

constexpr int Nbit= 200'000;

constexpr int sNbit= 21;



int nextX(const bitset<sNbit> &bsX, int popX){

  bitset<sNbit> X= bsX;



  int mod= 0;

  int base_mod= 1;

  while(X.any()){

    if(X.test(0)){

      mod= (mod+ base_mod) % popX;

    }



    base_mod= (2* base_mod) % popX;

    X >>= 1;

  }



  return mod;

}



int init(const bitset<Nbit> &bsX, vector<int> *base_mod, int div){

  if(div==0){ return 0; }

  else{

    const size_t N= (int)base_mod->size();



    bitset<Nbit> X= bsX;

    int mod= 0;

    base_mod->at(0)= 1 % div;

    for(size_t i=0; i<N; i++){

      if(X.test(i)){

        mod= (mod+ base_mod->at(i)) % div;

      }



      if(i+1 < N){

        base_mod->at(i+1)= (2* base_mod->at(i)) % div;

      }

    }



    return mod;

  }

}



int main(){

  int N;

  string X;

  cin >> N >> X;



  const bitset<Nbit> bsX(X);

  const int popX= (int)bsX.count();



  vector<int> offset_plus1(N);

  vector<int> offset_minus1(N);



  const int mod_popXplus1 = init(bsX, &offset_plus1 , popX+ 1);

  const int mod_popXminus1= init(bsX, &offset_minus1, popX- 1);

  

  for(int i=1; i<=N; i++){

    int bit_i= (bsX.test(N-i)) ? 0

                               : 1;

    int popXi= (bit_i==1) ? popX+ 1

                          : popX- 1;



    bitset<sNbit> bsXi;

    int ans_i= 0;

    while(popXi > 0){

      ans_i++;

      if(ans_i==1){

        int next= (bit_i==1) ? (mod_popXplus1+ offset_plus1.at(N-i)) % popXi

                             : (((mod_popXminus1- offset_minus1.at(N-i)) % popXi)+ popXi) % popXi;

        bsXi= bitset<sNbit>(next);

        popXi= (int)bsXi.count();

      }

      else{

        int next= nextX(bsXi, popXi);



        bsXi= bitset<sNbit>(next);

        popXi= (int)bsXi.count();

      }

    }



    cout << ans_i << endl;

  }

}

// Fastest known solution for this problem: