# coding: utf-8
original_string = input()[::-1]
check_string_count = int(input())
checkers = [input()[::-1] for i in range(check_string_count)]
for checker in checkers:
    for char in list(checker):
        if char not in original_string:
            checker = "#"
            break
    print(1 if checker in original_string else 0)