#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
//using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX
 

int f1(int x)
{
    int ans = 0;
    while(x)
    {
        int tot = 0;
        rep(i,0,27)
        {
            tot += (bool)(x&(1<<i));
        }
        x %= tot;
        ans++;
    }

    return ans;
}
 
     int p1[1000005], p2[1000005]; 

 
 
void solve()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    

    int tot = 0;
    loop(s)
        tot += (it=='1');


    if(tot == 0)
    {
        loop(s)
        {
            cout << 1 << endl;
        }
        return;
    }

    if(tot==1)
    {
        int i = 0;
        loop(s)
        {
            if(it=='1')
            {
                cout << 0 << endl;
                i++;
                continue;
            }

            if(s[s.size()-1]=='1')
            {
                cout << 2 << endl;
            }

            else
            {
                if(i==s.size()-1)
                    cout << 2 << endl;
                else
                    cout << 1 << endl;
            }
            i++;
        }

        return;
    }

    int curr1 = 1, curr2 = 1;
    rep(i,0,1000000)
    {
        curr1 %= tot+1;
        curr2 %= tot-1;
        p1[i] = curr1;
        p2[i] = curr2;
        curr1 *= 2;
        curr2 *= 2;
    }

    int a = 0, b = 0;
    loop(s)
    {
        a *= 2;
        a += (it == '1');
        a %= tot+1;
        b*=  2;
        b += (it == '1');
        b  %= tot-1;
    }


    rep(i,0,s.size()-1)
    {
        if(s[i]=='1')
        {
            int x =  (b-p2[s.size()-i-1] + 2*tot-2)%(tot-1);
            cout <<  f1(x)+1 << endl;
        }
        else
        {
            int x =  (a+p1[s.size()-i-1])%(tot+1);
            cout << f1(x)+1 << endl;
        }
    }
}
 
 
signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 19352