function Main(input) {
  let lines = input.split("\n");
  const count = parseInt(lines[0]);
  const array = [...lines[1]];
  for(let i = 0; i < count; i++){
    let copy_array = array.concat();
    if(copy_array[i] == "0"){copy_array[i] = "1"}
    else if(copy_array[i] == "1"){copy_array[i] = "0"};
    let tmp_num = parseInt(copy_array.join(''),2);
    let total = 0;
    const recursive = (num) => {
      if(num === 0) return;
      const tmp_array = [...num.toString(2)];
      let c = 0;
      tmp_array.map((e) => {
      	if(e == "1") c++;
      })
      total++;
      return recursive(num%c);
    }
    recursive(tmp_num);
    console.log(total);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));