program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,j,cnt,ans,b,imod,l,l2,cnt2
    character(200000):: x,x2

    read*, n
    read*, x

    do i=1,n
        x2 = x
        if(x(i:i) == '1') then
            x2(i:i) = '0'
        else
            x2(i:i) = '1'
        end if
        cnt=0
        ans = count_bit(x2)
        if (ans==0) then
            print'(i0)', 0
            cycle
        end if
        b=1
        imod=0

        do j=n,1,-1
            if(x2(j:j) == '1') imod=mod(imod+b,ans)
            b=mod(2*b,ans)
        end do
        cnt=1
        ans = imod
        do while(ans /= 0)
            l = 0
            l2 = 1
            do while(l2 <= ans)
                l=l+1
                l2=l2*2
            end do
            cnt2 = 0
            do j=1,l
                if (btest(ans,j-1)) cnt2=cnt2+1
            end do
            ans = mod(ans,cnt2)
            cnt=cnt+1
        end do
        print'(i0)', cnt
    end do

contains
function count_bit(x) result(ret)
    character(200000):: x
    integer(int32):: i,ret

    ret = 0
    do i=1,n
        if (x(i:i) == '1') ret=ret+1
    end do
end function


end program main