#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1100000
int Rank[MAX_N],x[MAX_N];
int SA[MAX_N];char S[MAX_N],T[MAX_N];int V;
bool Compare(int p,int q){
	if(Rank[p]<Rank[q])return true;
	if(Rank[p]>Rank[q])return false;
	int D1=-1,D2=-1;
	if(p+V<=S.size())D1=Rank[p+V];
	if(q+V<=S.size())D2=Rank[q+V];
	if(D1<D2)return true;
	return false;
}
void Build(){
	int SSIZE=strlen(S);
	for(int i=0;i<SSIZE;i++){SA[i]=i;Rank[i]=S[i];}
	SA[SSIZE]=SSIZE;Rank[SSIZE]=-1;
	for(V=1;V<=SSIZE;V*=2){
		sort(SA,SA+SSIZE+1,Compare);
		x[SA[0]]=0;
		for(int i=1;i<=SSIZE;i++){
			x[SA[i]]=x[SA[i-1]]+Compare(SA[i-1],SA[i]);
		}
		for(int i=0;i<=S.size();i++)Rank[i]=x[i];
	}
}
int hantei(string &V1,string &V2){
	int H=min(V1.size(),V2.size());
	for(int i=0;i<H;i++){
		if(V1[i]<V2[i])return -1;
		if(V1[i]>V2[i])return 1;
	}
	return 0;
}
int main(){
	cin>>S;int Q;cin>>Q;
	for(int i=0;i<Q;i++){
		cin>>T;int L=0,R=S.size()+1,M;
		while(L+1<R){
			M=(L+R)/2;
			if(hantei(S+SA[M],T)<=0)L=M;
			else{R=M;}
		}
		if(hantei(S+SA[L],T)==0)cout<<"1"<<endl;
		else cout<<"0"<<endl;
	}
	return 0;
}