#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//蟻本写経版 O(N*(logN)^2)
struct SuffixArray{
    VI sa;
    int k;
    const string S;
    VI rank,tmp;
    int n;

    SuffixArray(const string &str) : S(str){
        sa.resize(S.size()+1);
        rank.resize(S.size()+1);
        tmp.resize(S.size()+1);
        n = S.size();
        construct_sa();
    }

    // (rank[i],rank[i+k]),(rank[j],rank[j+k])を比較
    bool compare_sa(int i, int j){
        if(rank[i] != rank[j]) return rank[i] < rank[j];

        int ri = i + k <= n ? rank[i+k] : -1;
        int rj = j + k <= n ? rank[j+k] : -1;
        return ri < rj;
    }

    void construct_sa(){
        int n = S.length();
        for(int i = 0; i <= n; i++){
            sa[i] = i;
            rank[i] = i < n ? S[i] : -1;
        }

        for(k = 1; k <= n; k *= 2){
            sort(sa.begin(),sa.end(),[this](int a, int b){
                return compare_sa(a,b);
            });

            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];
            }
        }
    }

    bool contain(string T){
        int l = 0, r = n;
        while(r-l > 1){
            int mid = (r+l) / 2;
            if(S.compare(sa[mid], T.length(), T) < 0) l = mid;
            else r = mid;
        }
        return S.compare(sa[r], T.length(), T) == 0;
    }
};



signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; int Q;
    cin >> S;
    SuffixArray sa(S);
    cin >> Q;
    while(Q--){
        string T;
        cin >> T;
        cout << sa.contain(T) << endl;

    }

}

