#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>

using namespace std;
vector<int> helper(int N, string X);
vector<int> guchoku(int N, string X);
int calcCnt(long N);
long btCnt(long N);

int main(){
    int N;
    string X;
    vector<int> ans;
    cin >> N;
    cin >> X;
//    ans = guchoku(N, X);
    ans = helper(N, X);
/*    for(int i=0;i<N;i++){
        if(ans[i] != ans2[i]){
            cout << "ERROR:" << i << " " << ans[i] << "!=" << ans2[i] << endl;
        }
    }*/
    for(int a:ans){
        cout << a << endl;
    }
    return 0;
}

vector<int> guchoku(int N, string X){
    long a = 0;
    long sum=0;
    vector<int> ans;
    for(int i=0;i<N;i++){
        if(X[i] == '1'){
            a += (long)pow(2, N-1-i);
            sum ++;
        }
    }
    for(int i=0;i<N;i++){
        long test = a;
        if(X[i] == '1'){
            test -= pow(2, N-1-i);
            ans.push_back(calcCnt(test));
        }else{
            test += pow(2, N-1-i);
            ans.push_back(calcCnt(test));
        }
    }
    return ans;
}

vector<int> helper(int N, string X){
    vector<int> result;
    int plusMOD[N];
    int minusMOD[N];
    int ansArr[N];
    int cnt=0;
    for(int i=0;i<N;i++){
        if(X[i] == '1'){
            cnt++;
        }
    }
    if(cnt == 0){
        for(int i=0;i<N;i++){
            result.push_back(1);
        }
        return result;
        //all 1.
    }else if(cnt == 1){
        if(X[N-1] == '1'){
            for(int i=0;i<N-1;i++){
                result.push_back(2);
            }
            result.push_back(0);
            //22222.....220
        }else{
            for(int i=0;i<N-1;i++){
                if(X[i] == '1'){
                    result.push_back(0);
                }else{
                    result.push_back(1);
                }
            }
            result.push_back(2);
            //1111110111111
        }
        return result;
    }else{
        plusMOD[0] = 1 % (cnt+1);
        minusMOD[0] = 1 % (cnt-1);
        for(int i=1;i<N;i++){
            plusMOD[i] = plusMOD[i-1] * 2;
            plusMOD[i] %= (cnt+1);
            minusMOD[i] = minusMOD[i-1] * 2;
            minusMOD[i] %= (cnt-1);
        }
        int plus_base = 0;
        int minus_base = 0;
/*        cout << "PLUSMOD" ;
        for(int i=0;i<N;i++){
            cout << plusMOD[i];
        }
        cout << endl;
        cout << "MINUSMOD" ;
        for(int i=0;i<N;i++){
            cout << minusMOD[i];
        }
        cout << endl;*/
        for(int i=0;i<N;i++){
            if(X[i] == '1'){
                plus_base += plusMOD[N-1-i];
                plus_base %= (cnt+1);
                minus_base += minusMOD[N-1-i];
                minus_base %= (cnt-1);
            }
        }
//        cout << plus_base << "-" << minus_base << endl;
        for(int i=0;i<N;i++){
            if(X[i] == '1'){
                ansArr[i] = minus_base - minusMOD[N-1-i];
                ansArr[i] += (cnt-1);
                ansArr[i] %= (cnt-1);
            }else{
                ansArr[i] = plus_base + plusMOD[N-1-i];
                ansArr[i] += (cnt+1);
                ansArr[i] %= (cnt+1);
            }
        }
        for(int i=0;i<N;i++){
            result.push_back(calcCnt(ansArr[i]) + 1);
//            cout << calcCnt(ansArr[i]) + 1 << endl;
        }
        return result;
    }
}

int calcCnt(long N){
    int cnt=0;
    while(N != 0){
        N %= btCnt(N);
        cnt++;
    }
    return cnt;
}

long btCnt(long N){
    int cnt=0;
    while(N > 0){
        if((N & 0x01) == 1){
            cnt++;
        }
        N = (N>>1);
    }
    return cnt;
}




Measured memory_bytes: 7120