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

_max = pow(2, n-1)
itr = 0
hoge = False
one_num = bin(x).count("1")
while 1:
  n = x ^ _max
  if y[itr] == "0":
    hoge = True
    one_num += 1
  else:
    one_num -= 1
  count = 0
  while n != 0:
    n = n % one_num
    count += 1
    if 0 <= n <=1024:
      count += zuru[n]
      break
  print(count)
  n = x ^ _max
  _max = _max // 2
  itr += 1
  if hoge is True:
    one_num -= 1
    hoge = False
  else:
    one_num += 1
  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)))