#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline int BIT_popcount_L(const int x){
  return __builtin_popcount(x);
}
inline int BIT_popcount_L(const long long x){
  return __builtin_popcountll(x);
}
template<class S, class T> inline S moddw_L(S a, const T b){
  a %= b;
  if(a < 0){
    a += b;
  }
  return a;
}
int N;
char X[200000+2];
int res[300000];
long long mdp[200000+2];
long long mdm[200000+2];
long long tmdp;
long long tmdm;
int main(){
  int i;
  int j;
  int k;
  int mk;
  int pk;
  int c;
  rd(N);
  rd(X);
  for(i=(1);i<(300000);i++){
    j =BIT_popcount_L(i);
    res[i] = res[i%j] + 1;
  }
  k = 0;
  for(i=(0);i<(N);i++){
    X[i] -= '0';
  }
  for(i=(0);i<(N);i++){
    k += X[i];
  }
  pk = k + 1;
  mk =max_L(k - 1, 1);
  tmdp = tmdm = 0;
  for(i=(0);i<(N);i++){
    tmdp = (tmdp * 2 + X[i]) % pk;
  }
  for(i=(0);i<(N);i++){
    tmdm = (tmdm * 2 + X[i]) % mk;
  }
  mdp[0] = 1 % pk;
  for(i=(1);i<(N+1);i++){
    mdp[i] = (mdp[i-1] * 2) % pk;
  }
  mdm[0] = 1 % mk;
  for(i=(1);i<(N+1);i++){
    mdm[i] = (mdm[i-1] * 2) % mk;
  }
  for(i=(0);i<(N);i++){
    if(k==1 && X[i]==1){
      wt_L(0);
      wt_L('\n');
      continue;
    }
    if(X[i]==1){
      c =(moddw_L((tmdm - mdm[N-i-1]),mk));
      wt_L(res[c]+1);
      wt_L('\n');
    }
    else{
      c =(moddw_L((tmdp + mdp[N-i-1]),pk));
      wt_L(res[c]+1);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N;
// char X[2d5+2];
// int res[3d5];
// 
// ll mdp[2d5+2], mdm[2d5+2], tmdp, tmdm;
// 
// {
//   int i, j, k;
//   int mk, pk, c;
//   rd(N,X);
//   rep(i,1,3d5){
//     j = BIT_popcount(i);
//     res[i] = res[i%j] + 1;
//   }
// 
//   k = 0;
//   rep(i,N) X[i] -= '0';
//   rep(i,N) k += X[i];
// 
//   pk = k + 1;
//   mk = max(k - 1, 1);
//   tmdp = tmdm = 0;
//   rep(i,N) tmdp = (tmdp * 2 + X[i]) % pk;
//   rep(i,N) tmdm = (tmdm * 2 + X[i]) % mk;
//   mdp[0] = 1 % pk;
//   rep(i,1,N+1) mdp[i] = (mdp[i-1] * 2) % pk;
//   mdm[0] = 1 % mk;
//   rep(i,1,N+1) mdm[i] = (mdm[i-1] * 2) % mk;
// 
//   rep(i,N){
//     if(k==1 && X[i]==1) wt(0), continue;
//     if(X[i]==1){
//       c = (tmdm - mdm[N-i-1]) %% mk;
// //      wt(tmdm, mdm[N-i-1], mk, c);
//       wt(res[c]+1);
//     } else {
//       c = (tmdp + mdp[N-i-1]) %% pk;
// //      wt(tmdp, mdp[N-i-1], pk, c);
//       wt(res[c]+1);
//     }
//   }
// }


Measured memory_bytes: 8672