N = gets.to_i
X = gets.chomp

N.times do |i|
  str = X.dup
  str[i] = str[i] == '0' ? '1' : '0'
  n = str.to_i(2)
  cnt = 0
  while n != 0
    n %= n.to_s(2).count('1')
    cnt += 1
  end
  puts cnt
end