open Printf
open Scanf

let id x = x

let n = scanf "%d\n"id
let ns = Array.init n (fun _ -> scanf "%c" (fun c -> if c = '0' then 0 else 1))

exception Break

let log2 v = truncate (log (float v) /. log 2.0) + 1

let ns_value () =
    let result = ref 0 in
    let mul = ref 1 in
    for i = n - 1 downto 0 do
        if ns.(i) = 1 then result := !result + !mul;
        mul := !mul * 2
    done;
    !result

let popcount n =
    let c = ref 0 in
    let mul = ref 1 in
    for i = 0 to log2 n do
        if n land !mul <> 0 then incr c;
        mul := !mul * 2;
    done;
    !c

let f n =
    let c = ref 0 in
    let v = ref n in
    begin try while true do
        let p = popcount !v in
        if p = 0 then raise Break;
        incr c;
        v := !v mod p
    done with Break -> () end;
    !c

let run () =
    let rec rs = Array.init n (fun _ -> ref 0) in
    let v = ns_value () in
    let c = ref 0 in
    let mul = ref 1 in
    for i = n - 1 downto 0 do
        begin
            if ns.(i) = 0 then
                let w = v + !mul in
                rs.(i) := f w 
            else
                let w = v - !mul in
                rs.(i) := f w
        end;
        mul := !mul * 2
    done;
    for i = 0 to n - 1 do
        printf "%d\n" !(rs.(i))
    done
    
let () = run ()
