let tails s =
  let l = String.length s in
  let a = Array.init (l+1) (fun i -> if i = l then "" else String.sub s i (l-i)) in
  Array.sort compare a; a

let string_search a p =
  let al = Array.length a in
  let pl = String.length p in
  let rec iter l r =
    if r - l <= 1 then
      try if String.sub a.(r) 0 pl = p then 1 else 0 with _ -> 0
    else
      let m = (l + r) / 2 in
      if a.(m) = p then 1
      else if a.(m) > p then iter l m else iter m r
  in
  iter 0 al
       
let () =
  let t = read_line () in
  let ta = tails t in
  let q = read_int () in
  let rec loop x =
    if x = 0 then ()
    else let p = read_line () in
         string_search ta p |> string_of_int |> print_endline;
         loop (x-1)
  in loop q