unittest
{
	assert( [ "3", "011" ].solve == "2\n1\n1" );
	assert( [ "23", "00110111001011011001110" ].solve == "2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3" );
}



import core.bitop;
import std.conv;
import std.functional;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto x = input.front.map!( ( a ) => ( a == '1' ) ).array;
	
	auto p = x.count( true );
	auto rm = 0L;
	auto rp = 0L;
	foreach( i, b; x )
	{
		if( !b ) continue;
		rm = ( rm + memoize!remainder( 1, n - 1 - i, p - 1 ) ) % ( p - 1 );
		rp = ( rp + memoize!remainder( 1, n - 1 - i, p + 1 ) ) % ( p + 1 );
	}
	
	auto anss = new long[ n ];
	foreach( i, ref ans, b; lockstep( anss, x ) )
	{
		auto pp = ( b ) ? p - 1 : p + 1;
		auto rr = ( b ) ? rm : rp;
		if( b ) rr = ( rr + pp - memoize!remainder( 1, n - 1 - i, pp ) ) % pp;
		else    rr = ( rr + memoize!remainder( 1, n - 1 - i, pp ) ) % pp;
		ans++;
		
		for( ; 0 < rr; ans++ )
		{
			pp = rr._popcnt;
			rr = rr % pp;
		}
	}
	return anss.to!( string[] ).join( "\n" );
}

// ( n * 2 ^^ x ) % m を計算
long remainder( long n, long x, long m )
{
	if( x == 0 ) return n;
	else         return ( memoize!remainder( n, x - 1, m ) << 1 ) % m;
}
