let make_suffix_array t n =
  let ord = Array.make (n + 1) (-1) in
  String.iteri (fun i e -> ord.(i) <- Char.code e) t;
  let sa = Array.init (n + 1) (fun i -> i) in
  let rec doit k =
    if k > n then sa
    else begin
      let cmp a b =
        if ord.(a) <> ord.(b) then ord.(a) - ord.(b)
        else (if a + k <= n then ord.(a+k) else 0) - (if b + k <= n then ord.(b+k) else 0) in
      Array.sort cmp sa;
      let tmp = Array.make (n + 1) 0 in
      let rec aux i =
        if i <= n then begin
          tmp.(sa.(i)) <- tmp.(sa.(i-1)) + (if cmp sa.(i-1) sa.(i) < 0 then 1 else 0);
          aux (i + 1)
        end in
      aux 1;
      Array.iteri (fun i e -> ord.(i) <- e) tmp;
      doit (k * 2)
    end in
  doit 1

let () =
  let t = read_line () in
  let n = String.length t in
  let sa = make_suffix_array t n in
  let q = read_int () in
  let rec doit i =
    if i < q then begin
      let p = read_line () in
      let rec aux l r =
        if l >= r then r
        else begin
          let m = (l + r) / 2 in
          if compare (String.sub t sa.(m) (n - sa.(m))) p < 0 then aux (m + 1) r
          else aux l m
        end in
      let r = aux 0 n in
      begin match
        try Some (Str.search_forward (Str.regexp p) t sa.(r)) with _ -> None
      with
      | None -> Printf.printf "0\n"
      | _ -> Printf.printf "1\n"
      end;
      doit (i + 1)
    end in
  doit 0