from collections import defaultdict
from math import floor, log 


class NoMatch(Exception):
    pass


class IndexMatch:
    MAX_KEYLEN = 10

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

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

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

    def match(self, search_text):
        def _match(lo, hi):
            text = search_text[lo:hi]
            if hi-lo <= self.keylen:
                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)
            return indices

        if len(search_text) < self.keylen // 2:
            return search_text in self.particles

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

