from collections import defaultdict
from math import ceil, log


class IndexMatch:
    def __init__(self, text):
        self.text = text
        self.keylen = self._select_keylen()
        self.index = self._create_index()

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

    def _create_index(self):
        index = defaultdict(list)
        index[self.text[0]].append(0)
        st1 = [self.text[0]]
        st2 = []

        for i in range(1, len(self.text)):
            c = self.text[i]
            index[c].append(i)
            st2 = [c]
            while len(st1) > 0:
                s = st1.pop() + c
                index[s].append(i-len(s)+1)
                if len(s) <= self.keylen:
                    st2.append(s)
            st1, st2 = st2, st1

        return index

    def match(self, search_text):
        def _match(text):
            ls = len(text)
            if ls <= 2 or text in self.index:
                return self.index[text]

            mid = ls // 2
            pre = _match(text[:mid])
            post = _match(text[mid:])

            if len(pre) == 0 or len(post) == 0:
                return []

            indices = [i for i in pre if (i+mid) in post]
            self.index[text] = indices
            return indices

        return len(_match(search_text)) > 0


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()

