# coding: utf-8
import re

original_string = input()
check_string_count = int(input())
for count in range(check_string_count):
    checker = input()
    print(1 if re.search(checker, original_string) else 0)