{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections, TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Bits

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main = do
    n <- readLn :: IO Int
    x <- C.getLine
    let bitsSet = C.count '1' x
        xLow = bsToModInt (bitsSet - 1) x
        xHi  = bsToModInt (bitsSet + 1) x

    forM_ [0..n-1] (\i -> if bitsSet == 1 && C.index x i == '1'
                then print 0
                else let memo = if C.index x i == '1'
                            then minusMod
                                (bitsSet - 1)
                                xLow
                                (powMod (bitsSet - 1) 2 (n-i-1))
                            else plusMod
                                (bitsSet + 1)
                                xHi
                                (powMod (bitsSet + 1) 2 (n-i-1))
                    in print (fNaive memo+1)
        )

step n = n `rem` (popCount n)

fNaive = fNaiveAux 0
    where
        fNaiveAux ac 0 = ac
        fNaiveAux ac n = fNaiveAux (ac+1) (step n)

bsToModInt :: Int -> C.ByteString -> Int
bsToModInt md bs = let l = C.length bs
    in foldr1 (plusMod md) $
        map (\flipPos -> if C.index bs (l-flipPos-1) == '1'
                then powMod md 2 flipPos else 0) [l-1,l-2..0]

powMod :: Int -> Int -> Int -> Int
powMod mdl b e = powAux (b `rem` mdl) e 1 `mod` mdl
    where 
        powAux _ 0 !ac = ac
        powAux b e !ac = powAux (b*b `rem` mdl) (e `quot` 2)
            (if odd e then b*ac `rem` mdl else ac)

plusMod  mdl a b = (a + b) `rem` mdl
minusMod mdl a b = (a - b) `mod` mdl
