from typing import Dict, List


def calc_hash(input_v: List[int], target_len: int, input_len: int) -> set:
    global base, mask
    diff_len = input_len - target_len
    hash_set = set()

    bit_mask = 1
    for _ in range(target_len):
        bit_mask = (bit_mask * base) & mask
    hash_v = 0
    for i in range(target_len):
        hash_v = (hash_v * base + input_v[i]) & mask
    for i in range(diff_len):
        hash_set.add(hash_v)
        hash_v = (hash_v * base - bit_mask * input_v[i]
                  + input_v[i + target_len]) & mask
    hash_set.add(hash_v)

    return hash_set


if __name__ == "__main__":
    base = 123  # Ascii code after 'z'
    mask = (1 << 32) - 1  # Mask.

    input_v = [ord(s) for s in input()]
    input_len = len(input_v)

    checked_dict: Dict[int, set] = {}
    num_target = int(input())

    for _ in range(num_target):
        target_v = [ord(s) for s in input()]
        target_len = len(target_v)
        if input_len < target_len:
            print(0)
            continue
        magic_len = min(19, target_len)  # Magic number to reduce calc time.
        key = calc_hash(target_v, magic_len, target_len)
        if magic_len not in checked_dict:
            checked_dict[magic_len] = calc_hash(input_v, magic_len, input_len)
        if key.issubset(checked_dict[magic_len]):
            print(1)
        else:
            print(0)

