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