function main(input) {
  const n = parseInt(input[0]);
  const x = {};
  x.two = input[1];
  x.ten = parseInt(x.two, 2);

  const popc = x.two.split("").reduce((acc, value) => {
    return ((value==1)?(acc+1):(acc));
  }, 0);

  const x_min = x.ten%(popc-1);
  const x_pls = x.ten%(popc+1);

  let pow2 = [];
  pow2[0] = new Array(n);
  pow2[1] = new Array(n);
  pow2[0][0]=1;
  pow2[1][0]=1;
  for(let i=1;i<n;i++){
    pow2[0][i]=(pow2[0][i-1]*2)%(popc-1);
    pow2[1][i]=(pow2[1][i-1]*2)%(popc+1);
  }

  pow2[0]=pow2[0].reverse();
  pow2[1]=pow2[1].reverse();
  //console.log(pow2);

  for(let i=0;i<n;i++){
    let cnt = 0;
    if(x.ten!==0){
      const k = JSON.parse(JSON.stringify(x));

      if(k.two.split("")[i]==="0"){
        k.ten = (x_pls + pow2[1][i])%(popc+1);
        k.two = k.ten.toString(2);
      }else{
        k.ten = (x_min - pow2[0][i])%(popc-1);
        k.two = k.ten.toString(2);
      }
      cnt++;

      while(k.ten !== 0){
        const popcount = k.two.split("").reduce((acc, value) => {
          return ((value==1)?(acc+1):(acc));
        }, 0);
        k.ten = k.ten % popcount;
        k.two = k.ten.toString(2);
        cnt++;
      }
    }
    console.log(cnt);
  }  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));