#include "bits/stdc++.h"

using namespace std;

struct characters
{
    static int const size = 62;
    static int convert(char c)
    {
        // assert('a' <= c && c <= 'z');
        if ('a' <= c && c <= 'z')
        {
            return c - 'a';
        }
        else if ('A' <= c && c <= 'Z')
        {
            return 26 + c - 'A';
        }
        else
        {
            return 52 + c - '0';
        }
    }
    static char invert(int i)
    {
        // assert(0 <= i && i < size);
        if (0 <= i && i < 26)
        {
            return 'a' + i;
        }
        else if (26 <= i && i < 52)
        {
            return 'A' + i - 26;
        }
        else
        {
            return '0' + i - 52;
        }
    }
};

template <typename Characters>
class AhoCorasick
{
    static constexpr int invalidIndex = -1;

    struct PMA
    {
        int fail;
        std::vector<int> next, accept;

        PMA() : fail(invalidIndex), next(Characters::size, invalidIndex) {}
    };

    const int K;
    std::vector<std::unique_ptr<PMA>> nodes;

    int transition(int nodeIndex, char cc)
    {
        assert(0 <= nodeIndex && nodeIndex < (int)nodes.size());
        int c = Characters::convert(cc);
        int now = nodeIndex;
        while (nodes[now]->next[c] == invalidIndex && now != 0)
        {
            now = nodes[now]->fail;
        }
        now = nodes[now]->next[c];
        if (now == invalidIndex)
            now = 0;
        return now;
    }

  public:
    AhoCorasick(const std::vector<std::string> &ts) : K((int)ts.size())
    {
        const int rootIndex = 0;
        // root node
        nodes.push_back(std::make_unique<PMA>());
        nodes[rootIndex]->fail = rootIndex;
        for (int i = 0; i < K; i++)
        {
            int now = rootIndex;
            for (auto cs : ts[i])
            {
                int c = Characters::convert(cs);
                if (nodes[now]->next[c] == invalidIndex)
                {
                    nodes[now]->next[c] = (int)nodes.size();
                    nodes.push_back(std::make_unique<PMA>());
                }
                now = nodes[now]->next[c];
            }
            nodes[now]->accept.push_back(i);
        }

        std::queue<int> que;
        for (int c = 0; c < Characters::size; c++)
        {
            if (nodes[rootIndex]->next[c] != invalidIndex)
            {
                nodes[nodes[rootIndex]->next[c]]->fail = rootIndex;
                que.push(nodes[rootIndex]->next[c]);
            }
        }
        while (!que.empty())
        {
            int now = que.front();
            que.pop();
            for (int c = 0; c < Characters::size; c++)
            {
                if (nodes[now]->next[c] != invalidIndex)
                {
                    que.push(nodes[now]->next[c]);
                    int nxt = transition(nodes[now]->fail, Characters::invert(c));
                    nodes[nodes[now]->next[c]]->fail = nxt;
                    for (auto ac : nodes[nxt]->accept)
                    {
                        nodes[nodes[now]->next[c]]->accept.push_back(ac);
                    }
                }
            }
        }
    }
    std::vector<std::vector<int>> match(const std::string &str)
    {
        std::vector<std::vector<int>> ret(K);
        int now = 0;
        for (int i = 0; i < (int)str.size(); i++)
        {
            now = transition(now, str[i]);
            for (auto k : nodes[now]->accept)
            {
                ret[k].push_back(i);
            }
        }
        return ret;
    }
    std::vector<bool> contain(const std::string &str)
    {
        std::vector<bool> ret(K, false);
        int now = 0;
        for (int i = 0; i < (int)str.size(); i++)
        {
            now = transition(now, str[i]);
            for (auto k : nodes[now]->accept)
            {
                ret[k] = true;
            }
        }
        return ret;
    }
};

class SuffixArray
{
    int n;
    std::string str;
    std::vector<int> sa, rank;

    template <typename Compare>
    int binarySearch(const std::string &t)
    {
        int m = t.size();
        int lb = -1, ub = n + 1;
        while (ub - lb > 1)
        {
            int mid = (ub + lb) / 2;
            if (Compare()(strncmp(str.c_str() + sa[mid], t.c_str(), m), 0))
            {
                lb = mid;
            }
            else
            {
                ub = mid;
            }
        }
        return ub;
    }

  public:
    // 構築 O(n (logn)^2)
    SuffixArray(const std::string _s) : n(_s.size()), str(_s), sa(n + 1), rank(n + 1)
    {
        for (int i = 0; i <= n; i++)
        {
            sa[i] = i;
            rank[i] = i < n ? str[i] : -1;
        }
        std::vector<int> tmp(n + 1);
        for (int k = 1; k <= n; k *= 2)
        {
            // (rank[i], rank[i+k]), (rank[j], rank[j+k]) を比較
            auto compare_sa = [=](int i, int j) {
                if (rank[i] != rank[j])
                    return rank[i] < rank[j];
                else
                {
                    int ri = i + k <= n ? rank[i + k] : -1;
                    int rj = j + k <= n ? rank[j + k] : -1;
                    return ri < rj;
                }
            };
            std::sort(sa.begin(), sa.end(), compare_sa);
            tmp[sa[0]] = 0;
            for (int i = 1; i <= n; i++)
            {
                tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
            }
            for (int i = 0; i <= n; i++)
            {
                rank[i] = tmp[i];
            }
        }
    }
    // O(|t|logn)
    bool contain(const std::string &t)
    {
        int lb = 0, ub = n;
        while (ub - lb > 1)
        {
            int mid = (lb + ub) / 2;
            if (str.compare(sa[mid], t.size(), t) < 0)
                lb = mid;
            else
                ub = mid;
        }
        return str.compare(sa[ub], t.size(), t) == 0;
    }
    // 高さ配列 := 接尾辞配列における隣接要素で先頭何文字が共通しているか
    // つまり, lcp[i] = str[sa[i]..] と str[sa[i+1]..] の先頭共通文字数
    // O(n)
    std::vector<int> getLcp()
    {
        for (int i = 0; i <= n; i++)
            rank[str[i]] = i;
        int h = 0;
        std::vector<int> lcp(n + 1);
        for (int i = 0; i < n; i++)
        {
            int j = sa[rank[i] - 1];
            if (h > 0)
                h--;
            for (; j + h < n && i + h < n; h++)
            {
                if (str[j + h] != str[i + h])
                    break;
            }
            lcp[rank[i] - 1] = h;
        }
        return lcp;
    }
    std::vector<int> getSa()
    {
        return sa;
    }
    int lowerBound(const std::string &t)
    {
        return binarySearch<std::less<int>>(t);
    }
    int upperBound(const std::string &t)
    {
        return binarySearch<std::less_equal<int>>(t);
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string T;
    cin >> T;
    SuffixArray sa(T);
    int Q;
    cin >> Q;
    vector<string> s;
    while (Q--)
    {
        string t;
        cin >> t;
        cout << (sa.contain(t) ? 1 : 0) << endl;
    }
}



Measured memory_bytes: 16568