# coding: utf-8
original_string = list(map(ord, list(input())))
check_string_count = int(input())
checkers = [list(map(ord,list(input()))) for i in range(check_string_count)]
for checker in checkers:
    found = False
    for index in range(0, len(original_string)-len(checker)):
        if original_string[index] == checker[0]:
            found = True
            for checker_index in range(len(checker)):
                if checker[checker_index] != original_string[index + checker_index]:
                    found = False
                    break
            if found:
                print(1)
                break
    if not found:
        print(0)