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