# coding: utf-8

def searchPatterns(origin_string, length):
    patterns = []
    for index in range(0, len(origin_string)-(length-1)):
        patterns.append(original_string[index:index+length])
    return patterns

original_string = input()
original_patterns = [None for i in range(len(original_string))]
check_string_count = int(input())
checkers = [input() for i in range(check_string_count)]
for checker in checkers:
    if len(checker) > len(original_string):
        print(0)
        continue
    if original_patterns[len(checker)] == None:
        original_patterns[len(checker)] = searchPatterns(original_patterns, len(checker))
    print(1 if checker in original_patterns[len(checker)] else 0)