# 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
    sum_of_checker = sum(checker)
    if len(checker) > len(original_string):
        print(0)
        continue
    for index in range(0, len(original_string)):
        if (len(original_string)-len(checker)) < index:
            break
        if original_string[index] == checker[0]:
            found = True
            sum_of_origin = sum(original_string[index:index+len(checker)])
            if sum_of_origin != sum_of_checker:
                found = False
            if found:
                print(1)
                break
    if not found:
        print(0)