from collections import defaultdict


class IndexMatch:
    shift = 40
    size = 33554393

    def __init__(self, text):
        self.text = text
        self.index = self._create_index()

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

        for i in range(1, len(self.text)):
            index[self.text[i-1:i+1]].append(i-1)
            index[self.text[i]].append(i)

        return index

    def match(self, search_text):
        def _match(text):
            ls = len(text)
            if ls <= 2:
                return [(i, i+ls-1) for i in self.index[text]]

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

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

            indices = []
            for (s1, e1) in pre:
                (s2, e2) = self._find(post, e1+1)
                if s2 > 0:
                    indices.append(s1, e2)

            return indices

        return len(_match(search_text)) > 0

    def _find(self, ts, i):
        if len(ts) == 0:
            return (-1, -1)
        mid = len(ts) // 2
        s, e = ts[mid]
        if s > i:
            return self._find(ts[mid+1:], i)
        elif s < i:
            return self._find(ts[:mid], i)
        else:
            return (s, e)


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

