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

for i in range(len(x)):
  y = x.copy()
  if x[i] == "0":
    y[i] = "1"
  else:
    y[i] = "0"
  n = int("".join(y), 2)
  count = 0
  while n != 0:
    if 0 <= n <=1024:
      count += zuru[n]
      break
    one_num = bin(n)
    n = n % one_num.count("1")
    count += 1
  print(count)

### 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)))