use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

#[derive(PartialEq, Eq, Clone, Hash)]
struct Num {
    pows: Vec<i64>,
}

impl Num {
    fn new(bits: &str) -> Self {
        let bytes = bits.as_bytes();
        let mut pows = vec![];

        for i in 0..bytes.len() {
            if bytes[i] == b'1' {
                pows.push((bytes.len() - i) as i64 - 1);
            }
        }

        Self { pows }
    }

    fn popcount(&self) -> usize {
        self.pows.len()
    }

    fn rem(&self, value: i64) -> i64 {
        let mut rem = 0;
        for &p in self.pows.iter() {
            rem = (rem + raise(2, p, value)) % value;
        }
        rem
    }
}

fn calc_steps(limit: usize) -> Vec<i64> {
    let mut steps = vec![0; limit + 1];
    for i in 1..=limit {
        steps[i] = 1 + steps[i % i.count_ones() as usize];
    }
    steps
}

fn raise(base: i64, exp: i64, m: i64) -> i64 {
    if exp == 0 {
        return 1;
    } else if exp == 1 {
        return base % m;
    }

    if exp % 2 == 1 {
        return base % m * raise(base, exp - 1, m) % m;
    }

    let root = raise(base, exp / 2, m);
    (root * root) % m
}

fn solve(bits: &String) {
    let bytes = bits.as_bytes();
    let n = bytes.len();

    let num = Num::new(&bits[..]);
    let popcount = num.popcount() as i64;

    let rem_plus = num.rem(popcount + 1);
    let rem_minus = if popcount > 1 { num.rem(popcount - 1) } else { 0 };

    const MAX_POPCOUNT: usize = 200_000;
    let steps = calc_steps(MAX_POPCOUNT);

    for i in 0..n {
        let res = if bytes[i] == b'0' {
            let m = popcount + 1;
            let v = (rem_plus % m + raise(2, (n - i - 1) as i64, m)) % m;
            1 + steps[v as usize]
        } else if popcount == 1 {
            0
        } else {
            let m = popcount - 1;
            let v = (rem_minus % m + m - raise(2, (n - i - 1) as i64, m)) % m;
            1 + steps[v as usize]
        };
        println!("{}", res);
    }
}

fn main() {
    let mut reader = TokenReader::new();
    let _ = reader.next::<usize>();
    let bits = reader.next();
    solve(&bits);
}


Measured memory_bytes: 4740