use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().chars().collect()
}

fn digit(n: u64) -> u64 {
    if n == 0 {
        return 1;
    }
    for i in 0..200001u32 {
        if n < 2u64.pow(i) {
            return i as u64;
        }
    }
    20u64
}

fn calc(x: &Vec<char>, count: u64) -> u64{
    let d = digit(count);
    // println!("d = {}", d);
    let mut buf: u64 = 0;
    for i in 0..d-1 {
        buf *= 2;
        buf += x[i as usize] as u64 - '0' as u64;
    }
    // println!("init buf = {}", buf);
    for i in d as usize - 1..x.len() {
        buf *= 2;
        buf += x[i] as u64 - '0' as u64;
        buf %= count;
        // println!("buf = {}", buf);
    }
    buf
}

fn digit_sum(n: u64) -> u64 {
    let mut m = n;
    let mut sum = 0u64;
    let mut i = 20u32;
    while i > 0 {
        let l = m / 2u64.pow(i);
        sum += l;
        m -= l * 2u64.pow(i);
        i -= 1;
    }
    sum + m
}

fn f(n: u64) -> u64 {
    if n == 0 {
        return 0;
    }
    let mut n = n;
    let mut count = 0;
    while n > 0 {
        count += 1;
        // println!("digit_sum = {}", digit_sum(n));
        n %= digit_sum(n);

    }
    count
}

fn main() {
    let n: u64 = input();
    let x = input_char_vec();

    let mut num = 0;
    // for c in &x {
    //     num *= 2;
    //     num += *c as u64 - '0' as u64;
    // }
    // println!("num = {}", num);

    let mut count = 0;
    for c in &x {
        if *c == '1' {
            count += 1;
        }
    }
    // println!("count = {}", count);
    if count == 0 {
        for i in 0..n {
            println!("1");
        }
        return;
    }
    if count == 1 {
        let a = calc(&x, count + 1);
        // println!("a = {}", a);
        let mut a_vec = vec![1 % (count + 1); n as usize];
        for i in 1..n as usize {
            a_vec[i] = a_vec[i - 1] * 2 % (count + 1);
        }
        // println!("{:?}", a_vec);
        for i in 0..n as usize {
            if x[i] == '1' {
                println!("0");
            } else {
                let m = (a + a_vec[n as usize - 1 - i]) % (count + 1);
                println!("{}", f(m) + 1);
            }
        }
        return;
    }

    let a = calc(&x, count + 1);
    let b = calc(&x, count - 1);
    // println!("a = {}, b = {}", a, b);
    let mut a_vec = vec![1 % (count + 1); n as usize];
    let mut b_vec= vec![1 % (count - 1); n as usize];
    for i in 1..n as usize {
        a_vec[i] = a_vec[i - 1] * 2 % (count + 1);
        b_vec[i] = b_vec[i - 1] * 2 % (count - 1);
    }
    // println!("{:?}", a_vec);
    // println!("{:?}", b_vec);
    for i in 0..n as usize {
        if x[i] == '1' {
            let m = (b + count - 1 - b_vec[n as usize - 1 - i]) % (count - 1);
            println!("{}", f(m) + 1);
        } else {
            let m = (a + a_vec[n as usize - 1 - i]) % (count + 1);
            println!("{}", f(m) + 1);
        }
    }
}


Measured memory_bytes: 5860