#pragma region templates
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using i8  = std::int8_t;
using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using u8  = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using f32 = float;
using f64 = double;
using vi32  = std::vector<i32>;
using vu32  = std::vector<u32>;
using vi64  = std::vector<i64>;
using vu64  = std::vector<u64>;
using vvi32 = std::vector<vi32>;
using vvu32 = std::vector<vu32>;
using vvi64 = std::vector<vi64>;
using vvu64 = std::vector<vu64>;
using pi32  = std::pair<i32,i32>;
using pi64  = std::pair<i64,i64>;

#define FOR(i,a,b) for(i64 i=(a), i##_len=(b); i<i##_len; ++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) for(i64 i=1LL; i<=static_cast<i64>(n); ++i)
#define RFOR(i,a,b) for(i64 i=(a), i##_len=(b); i>i##_len; --i)
#define RFORS(i,n) RFOR(i,n,0)

#define ALL(obj) (obj).begin(),(obj).end()
#define CLR(ar,val) memset(ar, val, sizeof(ar))
#define SZ(obj) (static_cast<i32>(obj.size()))
#define cauto const auto&
#define pb push_back
#define mp make_pair

const i32 dx[4]={1,0,-1,0};
const i32 dy[4]={0,1,0,-1};
const i32 INF32 = 0x3F3F3F3F;
const i64 INF64 = 0x3F3F3F3F3F3F3F3F;

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

class range {
private:
    struct I {
        i32 x;
        i32 operator*() { return x; }
        bool operator!=(I& lhs) { return x<lhs.x; }
        void operator++() { ++x; }
    };
    I i,n;
public:
    explicit range(int n) : i({0}), n({n}) { }
    range(int i,int n) : i({i}), n({n}) { }
    I& begin() { return i; }
    I& end() { return n; }
};

struct IoSetup {
    IoSetup() {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(10);
        std::cerr << std::fixed << std::setprecision(10);
    }
};/// cin,coutを使うときは iosetup をここにつける

template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first >> p.second;return is; }
template<typename A, typename B> std::ostream &operator<<(std::ostream &os, const std::pair<A, B>& p) { os << p.first << ' ' << p.second;return os; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for(T& in : v) is >> in; return is; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) { for(i32 i = 0; i < SZ(v); i++) os << v[i] << (i+1 != SZ(v) ? " " : ""); return os; }
#pragma endregion

#pragma region Suffix-Array

struct SuffixArray {
    vi32 SA;
    const std::string s;

    SuffixArray(const std::string& str) : s(str) {
        SA.resize(SZ(s));
        std::iota(ALL(SA), 0);
        std::sort(ALL(SA), [&](i32 a, i32 b) { return s[a] == s[b] ? a > b : s[a] < s[b]; });
        vi32 classes(SZ(s)), c(ALL(s)), cnt(SZ(s));
        for (i32 len = 1; len < SZ(s); len <<= 1) {
            for (i32 i = 0; i < SZ(s); i++) {
                if (i > 0 && c[SA[i-1]] == c[SA[i]] && SA[i-1] + len < SZ(s) && c[SA[i-1] + len / 2] == c[SA[i] +len / 2]) {
                    classes[SA[i]] = classes[SA[i-1]];
                } else {
                    classes[SA[i]] = i;
                }
            }
            std::iota(ALL(cnt), 0);
            std::copy(ALL(SA), begin(c));

            for (i32 i = 0; i < SZ(s); i++) {
                int s1 = c[i] - len;
                if(s1 >= 0) SA[cnt[classes[s1]]++] = s1;
            }
            classes.swap(c);
        }
    }

    i32 operator[](i32 k) const {
        return SA[k];
    }

    size_t size() const {
        return s.size();
    }

    bool lt_substr(const std::string& t, i32 si = 0, i32 ti = 0) {
        i32 sn = SZ(s), tn = SZ(t);
        while(si < sn && ti < tn) {
            if(s[si] < t[ti]) return true;
            if(s[si] > t[ti]) return false;
            ++si, ++ti;
        }
        return si >= sn && ti < tn;
    }

    i32 lower_bound(const std::string& t) {
        i32 low = -1, high = SZ(SA);
        while (high - low > 1) {
            i32 mid = (low + high) / 2;
            if (lt_substr(t, SA[mid])) low = mid;
            else high = mid;
        }
        return high;
    }

    pi32 lower_upper_bound(std::string& t) {
        i32 idx = lower_bound(t);
        i32 low = idx - 1, high = SZ(SA);
        t.back()++;
        while(high - low > 1) {
            int mid = (low + high) / 2;
            if (lt_substr(t, SA[mid])) low = mid;
            else high = mid;
        }
        t.back()--;
        return {idx, high};
    }

    void output() {
        for(i32 i = 0; i < SZ(s); i++) {
          std::cout << i << ": " << s.substr(SA[i]) << std::endl;
        }
    }
};

#pragma endregion

#pragma region Longest Common Prefix Array

struct LongestCommonPrefixArray {
    const SuffixArray& SA;
    vi32 LCP, rank;

    LongestCommonPrefixArray(const SuffixArray& SA) : SA(SA), LCP(SA.size()) {
        rank.resize(SA.size());
        for (i32 i = 0; i < SA.size(); i++) {
            rank[SA[i]] = i;
        }
        for (i32 i = 0, h = 0; i < SA.size(); i++) {
            if (rank[i] + 1 < SA.size()) {
                for(i32 j = SA[rank[i] + 1]; std::max(i, j) + h < SA.size() && SA.s[i + h] == SA.s[j + h]; ++h);
                LCP[rank[i] + 1] = h;
                if(h > 0) --h;
            }
        }
    }

    i32 operator[](i32 k) const {
      return LCP[k];
    }

    size_t size() const {
        return LCP.size();
    }

    void output() {
        for(i32 i = 0; i < size(); i++) {
            std::cout << i << ": " << LCP[i] << " " << SA.s.substr(SA[i]) << std::endl;
        }
    }
};

#pragma endregion

i32 main() {
    /* https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/14/ALDS1_14_D */
    using namespace std;
    
    string s; cin >> s;
    i32 Q; cin >> Q;

    SuffixArray sa(s);

    while (Q--) {
        string t; cin >> t;
        auto range = sa.lower_upper_bound(t);
        cout << (range.first != range.second) << endl;
    }
}


Measured memory_bytes: 19560