from collections import defaultdict
from math import floor, log


class NoMatch(Exception):
    pass


class HashIndex:
    MAX_KEYLEN = 15
    MAX_SEARCH = 1000

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

    def _select_keylen(self):
        chars = len(set(list(self.text)))
        textlen = len(self.text)
        if chars > 1:
            return min(floor(log(textlen, chars)), self.MAX_KEYLEN)
        else:
            return self.MAX_SEARCH+1

    def _create_index(self):
        index = defaultdict(set)
        particles = set()
        if self.keylen == self.MAX_SEARCH+1:
            for i in range(self.keylen+1):
                particles.add(self.text[0:i+1])
        else:
            for i in range(len(self.text)+1):
                for j in range(max(i-self.keylen, 0), i):
                    if i - j < self.keylen:
                        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):
            length = hi - lo
            if length == self.keylen:
                return self.index[search_text[lo:hi]]

            if length < self.keylen*2:
                results = set()
                pre = search_text[lo:lo+self.keylen]
                post = search_text[lo+self.keylen:hi]
                if post in self.particles:
                    for i in self.index[pre]:
                        if post == self.text[i+self.keylen:i+(hi-lo)]:
                            results.add(i)
                return results

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

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

            return _merge(pre, post, mid-lo)

        def _merge(idx1, idx2, shift):
            return set(i for i in idx1 if i + shift in idx2)

        length = len(search_text)
        if length < self.keylen:
            # print('check_size', search_text)
            return search_text in self.particles

        # align by key length
        k = floor(log(length/self.keylen, 2))
        b = self.keylen * 2**k
        if length - self.keylen < b < length and k > 0:
            b = self.keylen * 2**(k-1)

        try:
            if b + self.keylen < length:
                match = _merge(_match(0, b), _match(b, length), b)
            else:
                match = _match(0, length)
            return len(match) > 0
        except:
            return False

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

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


if __name__ == '__main__':
    run()

