let pn = 1000000007

let pow x n =
  let rec doit x n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (x * x) (n / 2) acc
    else doit (x * x) (n / 2) (acc * x) in
  doit x n 1

let fold_left f init s n =
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (f acc s.[i]) in
  doit 0 init

let () =
  let t = read_line () in
  let n = String.length t in
  let h = Array.make (n + 1) 0 in
  let hash x c = x * pn + Char.code c in
  String.iteri (fun i c -> h.(i+1) <- hash h.(i) c) t;
  let include_p p =
    let m = String.length p in
    let v = fold_left hash 0 p m in
    let x = pow pn m in
    try
      for i = 0 to n - m do
        if h.(i+m) - h.(i)*x = v then raise Exit
      done;
      false
    with Exit -> true in
  let q = read_int () in
  for _ = 0 to q - 1 do
    Printf.printf "%d\n" (if read_line () |> include_p then 1 else 0);
  done