# -*- coding: utf-8 -*-
import sys
from collections import OrderedDict


def main():
    inputStr = sys.stdin.read()
    lines = inputStr.split("\n")
    text, words = lines[0], lines[2:-1]
    words_by_length = {}
    for i, word in enumerate(words):
        if len(word) in words_by_length:
            words_by_length[len(word)].append((i, word))
        else:
            words_by_length[len(word)] = [(i, word)]
    words_by_length = OrderedDict(sorted(words_by_length.items(), key=lambda t: t[0]))
    found_indices = set([])
    text_length = len(text)
    for i in range(text_length):
        for word_length, words_by_index in words_by_length.items():
            if i + word_length > text_length:
                break
            sliced = text[i:(i + word_length)]
            founds = []
            for j, (index, word) in enumerate(words_by_index):
                if sliced == word:
                    found_indices.add(index)
                    founds.insert(0, j)
            for j in founds:
                words_by_index.pop(j)

    for i in range(len(words)):
        if i in found_indices:
            print(1)
        else:
            print(0)


if __name__ == '__main__':
    main()

