#include<bits/stdc++.h>

#define rank Rank

using namespace std;

const int N=1e6+10;

int n,k;
int sa[N];
int rank[N];
int tmp[N];

string S,T;

bool cmp(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;
    }
}

void getSa()
{
    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<<=1)
    {
        sort(sa,sa+n+1,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 contain()
{
    int l=0,r=S.length();
    while(r-l>1)
    {
        int mid=(l+r)>>1;
        if(S.compare(sa[mid],T.length(),T)<0) l=mid;
        else r=mid;
    }
    return S.compare(sa[r],T.length(),T)==0;
}

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

    cin>>S;

    int number;

    cin>>number;

    getSa();

    while(number--)
    {
        cin>>T;
        cout<<contain()<<endl;
    }

    return 0;
}

