# coding: utf-8
original_string = input()
check_string_count = int(input())
checkers = [input() for i in range(check_string_count)]
for checker in checkers:
    if len(checker) > 10:
        half_checker = checker[0:int(len(checker)/2)]
        if half_checker not in original_string:
            continue
    print(1 if checker in original_string else 0)