#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


class suffixArray{
    string field;
    VI rank;
    VI sa;
    int k;
public:
    suffixArray(string s)
        : field(s), rank(s.length() + 1), sa(s.length() + 1){
        construct_sa();
    }
private:
    void construct_sa(){
        int n = field.length();
        REPS(i, n){
            sa[i] = i;
            rank[i] = (i<n ? field[i] : -1);
        }
        VI tmp(n + 1);
        for(k = 1; k <= n; k *= 2){
            auto comp_sa = [&](int i, int j){
                if(this->rank[i] != this->rank[j]) return this->rank[i] < this->rank[j];
                int ri = (i+k<=SZ(field) ? this->rank[i+k] : -1);
                int rj = (j+k<=SZ(field) ? this->rank[j+k] : -1);
                return ri < rj;
            };
            sort(ALL(sa), comp_sa);

            tmp[sa[0]] = 0;
            FORS(i, 1, n){
                tmp[sa[i]] = tmp[sa[i-1]] 
                           + (comp_sa(sa[i-1], sa[i]) ? 1 : 0);
            }
            REPS(i, n)
                rank[i] = tmp[i];
        }
    }
public:
    bool contain(string purpose){
        int m = purpose.length();
        int a = 0, b = field.length();
        while(b-a > 1){
            int c = (a+b) / 2;
            if(field.compare(sa[c], m, purpose) < 0) a = c;
            else b = c;
        }
        return !field.compare(sa[b], m, purpose);
    }
};

int main(){
    string T; cin >> T;
    suffixArray SA(T);
    int Q; cin >> Q;
    REP(i, Q){
        string P; cin >> P;
        cout << (SA.contain(P) ? 1 : 0) << "\n";
    }
    return 0;
}

