from collections import defaultdict
from math import floor, log


class NoMatch(Exception):
    pass


class IndexMatch:

    def __init__(self, text):
        self.text = text
        self.keylen = self._select_keylen()
        self.index = self._create_index()
        # print(self.index)

    def _select_keylen(self):
        chars = set(list(self.text))
        return floor(log(len(self.text), len(chars)))

    def _create_index(self):
        index = defaultdict(set)
        for i in range(len(self.text)+1):
            for j in range(max(i-self.keylen, 0), i):
                index[self.text[j:i]].add(j)
        return index

    def match(self, search_text):
        def _match(lo, hi):
            text = search_text[lo:hi]
            if hi-lo <= self.keylen or text in self.index:
                # print(text, self.index[text])
                return self.index[text]

            mid = (lo + hi) // 2
            pre = _match(lo, mid)
            post = _match(mid, hi)

            if len(pre) == 0 or len(post) == 0:
                raise NoMatch()

            indices = set(i for i in pre if i+mid-lo in post)
            self.index[text] = indices
            # print(text, hi, lo, mid, len(pre), len(post), len(indices))
            return indices

        try:
            match = _match(0, len(search_text))
            return len(match) > 0
        except NoMatch:
            return False


def run():
    s1 = input()
    n = int(input())

    matcher = IndexMatch(s1)
    for _ in range(n):
        s2 = input()
        if matcher.match(s2):
            print(1)
        else:
            print(0)


if __name__ == '__main__':
    run()

