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 3, 2, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1]

_max = pow(2, n-1)
while 1:
  n = x ^ _max
  count = 0
  while n != 0:
    n = n % bin(n).count("1")
    count += 1
    if 0 <= n <=1024:
      count += zuru[n]
      break
  print(count)
  n = x ^ _max
  _max = _max // 2
  if _max == 0:
    break

### FIXED CODE ###

N=int(input())
X=input()
Y=int(X,2)
Z=Y
C=X.count('1')
if C==1:
  for i in range(N):
    if X[i]=='1':
      print(0)
    elif i==N-1:
      print(2)
    else:
      print(1)
  exit()
Y,Z=Y%(C+1),Z%(C-1)

def f(x):
  if x==0:
    return 0
  return 1+f(x%bin(x).count('1'))

for i in range(N):
  if X[i]=='1':
    print(1+f((Z-pow(2,N-i-1,C-1))%(C-1)))
  else:
    print(1+f((Y+pow(2,N-i-1,C+1))%(C+1)))