#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<chrono>
#include<unistd.h>
using namespace std;

#define MAX 1100000
#define MAX_P 1100
#define LIMITX 10

string T, P;
int Tsize, Psize;
pair<int,int> cont[MAX];
pair<int,int> contp;
bool flag;

class index{
	public:
	int in, len = 0, tlen = 0;
	inline bool operator< (const index right ) {
		int rl = Tsize-right.in, ll = Tsize-in;
		int ma = rl<ll?rl:ll, s = 0;
		if(T[in] == T[right.in])s = min(cont[in].second-in,cont[right.in].second-right.in) + 1;
		for(int i = s; i < ma; i++){
			if(T[in+i] < T[right.in+i]) return true;
			if(T[in+i] > T[right.in+i]) return false;
		}
		return ll<rl;
	}
	inline bool operator< (const string right ) {
		int rl = Psize, ll = Tsize-in, ma = (ll<rl?ll:rl), s = 0;
			if(T[in] == right[0])s = min(cont[in].second-in,contp.second) + 1;
		for(int i = s; i < ma; i++){
			if(T[in+i] < right[i]) return true;
			if(T[in+i] > right[i]) return false;
		}
		return ll<rl;
	}
	template<typename U>
	inline bool operator=(const U& ohter){
		in = ohter;
	}
};
index in, in2;
vector<index> SA;

char slect_pivot_m(int low, int high, int n){
	char a = T[SA[low].in+n], b = T[SA[(low+high)/2].in+n], c = T[SA[high].in+n];
	if(a > b) swap(a,b);
	if(b > c){
		b = c;
		if(a > b) b = a;
	}
	return b;
}

void multikey_quicksort(int low, int high, int n){
	if(high-low <= LIMITX){
		sort(SA.begin()+low,SA.begin()+high+1);
	} else {
		char pivot = slect_pivot_m(low,high,n);
		int i, j, m1, m2;
		i = m1 = low;
		j = m2 = high;
		while(true){
			while(i <= j){
				char k;
				k = T[SA[i].in+n];
				if(k > pivot) break;
				if(k == pivot){
					swap(SA[i],SA[m1]);
					m1++;
				}
				i++;
			}
			while(i <= j){
				char k;
				k = T[SA[j].in+n];
				if(k < pivot) break;
				if(k == pivot){
					swap(SA[j],SA[m2]);
					m2--;
				}
				j--;
			}
			if(i > j) break;
			swap(SA[i],SA[j]);
			i++;
			j--;
		}
		for(int k = 0, mi = min(m1-low,i-m1); k < mi; k++ ){
			swap(SA[low+k],SA[j-k]);
		}
		m1 = low + (i - m1);
		for(int k = 0, mi = min(high-m2,m2-j); k < mi; k++ ){
			swap(SA[i+k],SA[high-k]);
		}
		m2 = high - (m2- j) + 1;
		if(low < m1)multikey_quicksort(low,m1-1,n);
		if(m1 < m2 && T[SA[m2].in+n] != '\0') multikey_quicksort(m1,m2-1,n+1);
		if(m2 <= high)multikey_quicksort(m2,high,n);
	}
}

void init(){
	int size = Tsize, count = 0;
	for(int i = 0,j = size-1; i < size; i++,j--){
		index temp; temp = i;
		SA.push_back(temp);
		if(i&&T[i-1] == T[i]){
			cont[i].first = cont[i-1].first;
		} else cont[i].first = i,count++;
		if(j != size-1&&T[j] == T[j+1]){
			cont[j].second = cont[j+1].second;
		}else cont[j].second = j;
	}
	if(count <= 100)sort(SA.begin(),SA.end());
	else multikey_quicksort(0, Tsize-1,0);

}

bool equal(string str, index com){
	int len = str.size(), clen = Tsize - com.in;
	if(len > clen) return false;
	for(int i = 0; i < len; i++){
		if(str[i] != T[com.in+i]) return false;
	}
	return true;
}

bool solve(string str){
	decltype(SA)::iterator it = lower_bound(SA.begin(),SA.end(),str);
	if(it == SA.end())return false;
	else return equal(str,*it);
}

int main(){
	int Q, p;
	cin>>T;
	T += '\0';
	Tsize = T.size()-1;
	init();
	cin>>Q;
	
	for(int i = 0; i < Q; i++){
		cin>>P;
		Psize = P.size();
		for(int k = 0,j = Psize-1; k < Psize; k++,j--){
			if(k&&P[k-1] == P[k]){
				contp.first = contp.first;
			} else contp.first = k;
			if(j != Psize-1&&P[j] == P[j+1]){
				contp.second = contp.second;
			}else contp.second = j;
		}
		cout<<solve(P)<<endl;
	}
	return 0;
}




Measured memory_bytes: 24704