exception Not_equal of int

let cmp_sa rank a b n k =
  if rank.(a) <> rank.(b) then compare rank.(a) rank.(b)
  else
    compare
      (if a + k <= n then rank.(a+k) else (-1))
      (if b + k <= n then rank.(b+k) else (-1))

let construct_sa t n =
  let sa = Array.make (n + 1) 0 in
  let rank = Array.make (n + 1) 0 in
  let tmp = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    sa.(i) <- i;
    rank.(i) <- Char.code t.[i];
  done;
  sa.(n) <- n;
  rank.(n) <- (-1);
  let k = ref 1 in
  while !k <= n do
    Array.sort (fun a b -> cmp_sa rank a b n !k) sa;
    tmp.(sa.(0)) <- 0;
    for i = 1 to n do
      tmp.(sa.(i)) <- tmp.(sa.(i-1)) + cmp_sa rank sa.(i-1) sa.(i) n !k;
    done;
    for i = 1 to n do
      tmp.(sa.(i)) <- -tmp.(sa.(i));
    done;
    for i = 0 to n do rank.(i) <- tmp.(i) done;
    k := !k * 2;
  done;
  sa

let range_cmp t n offset p k =
  if n - offset < k then (-1)
  else
    try
      for i = 0 to k - 1 do
        if t.[i+offset] <> p.[i] then
          raise (Not_equal (compare t.[i+offset] p.[i]));
      done;
      0
    with Not_equal i -> i

let () =
  let t = read_line () in
  let n = String.length t in
  let sa = construct_sa t n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    let p = read_line () in
    let k = String.length p in
    let l = ref 0 in
    let r = ref (n + 1) in
    while !l + 1 < !r do
      let m = (!l + !r) / 2 in
      let ret = range_cmp t n sa.(m) p k in
      if ret <= 0 then l := m
      else r := m;
    done;
    Printf.printf "%d\n" (if range_cmp t n sa.(!l) p k = 0 then 1 else 0);
  done