#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1000005

//Suffix_Array
//O(|T|log|S|) S??????????????????T????????????????????????????´¢
#define rank A
int n,Len;
int rank[MAX_N+1];
int tmp[MAX_N+1];

//(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+Len<=n?rank[i+Len]:-1;
  int rj=j+Len<=n?rank[j+Len]:-1;
  return ri<rj;
}

//?????????S?????\?°??????????????§????
void construct_sa(string S,int *sa){
  n=S.length();
  //?????????????????????????????????????????????????????????
  for(int i=0;i<=n;i++){
    sa[i]=i;
    rank[i]=i<n?S[i]:-1;
  }
  //k????????????????????????????????????????????¨???????????????2k????????§?????????
  for(Len=1;Len<=n;Len*=2){
    sort(sa,sa+n+1,compare_sa);
    //?????£??????tmp????¬?????????????????¨?????????????rank?????£??\
    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];
  }
}

//S??????????????????T????????????????????????????´¢??????
bool contain(string S,int *sa,string T){
  int left=0,right=S.length();
  while(right-left>1){
    int mid=(left+right)/2;
    if(S.compare(sa[mid],T.length(),T)<0)left=mid;
    else right=mid;
  }
  return S.compare(sa[right],T.length(),T)==0;
}


string t,p;
int q,sa[MAX_N];
int main(){
  cin>>t;
  construct_sa(t,sa);
  cin>>q;
  while(q--){
    cin>>p;
    if(contain(t,sa,p))cout<<1<<endl;
    else cout<<0<<endl;
  }
  return 0;
}