#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n,k;
vector<ll> Rank;
vector<ll> tmp;
vector<ll> sa;
string str;


bool less_cmp(ll a,const string &s){
    for(ll i=0;i<s.size();i++){
        if(i+a>=n){return true;}
        if(str[i+a]!=s[i]){return str[i+a]<s[i];}
    }
    return false;
}

bool equal_cmp(ll a,const string &s){
    for(ll i=0;i<s.size();i++){
        if(i+a>=n){return false;}
        if(str[i+a]!=s[i]){return false;}
    }
    return true;
}

bool cmp(ll i,ll j){
    if(Rank[i]!=Rank[j]){return Rank[i]<Rank[j];}
    return (i+k<=n?Rank[i+k]:-1)<(j+k<=n?Rank[j+k]:-1);
}

void build(const string &s){
    n=s.size();
    sa.resize(n+1);
    Rank.resize(n+1);
    tmp.resize(n+1);
    for(int i=0;i<=n;i++){
        sa[i]=i;
        Rank[i]=i<n?s[i]:-1;
    }
    for(k=1;k<=n;k<<=1){
        sort(sa.begin(),sa.end(),cmp);
        tmp[sa[0]]=0;
        for(int i=1;i<=n;i++){
            tmp[sa[i]]=tmp[sa[i-1]]+(cmp(sa[i-1],sa[i])?1:0);
        }
        for(int i=0;i<=n;i++){
            Rank[i]=tmp[i];
        }
    }
}


bool search(const string &s){
    ll l=0,r=n;
    while(r-l>=10){
        ll m=l+(r-l)/2;
        if(less_cmp(sa[m],s)){l=m+1;}
        else{r=m;}
    }
    for(ll i=l;i<=r;i++){
        if(equal_cmp(sa[i],s)){return true;}
    }
    return false;
}




int main(){
    cin>>str;
    build(str);
    /*
    cout<<endl;
    for(int i=0;i<=str.size();i++){
        cout<<i<<" "<<Rank[sa[i]]<<endl;
        for(ll t=sa[i];t<str.size();t++){cout<<str[t];}
        cout<<endl;
    }
     */
    ll q;
    cin>>q;
    while(q--){
        string p;
        cin>>p;
        cout<<search(p)<<endl;
    }
    
    
    return 0;
}

