#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;
typedef vector<int> V;

const int inf = 1e7;

int n;
string t;
int q;
string p[10000];
int sa[20][1000000];
int isa[1000000];
int lcp[2 << 20];

int stu(int i, int x, int k, int l, int r){
	if(r <= i || i < l){
		return lcp[k];
	}
	if(i <= l && r <= i + 1){
		return lcp[k] = x;
	}
	int m = (l + r) / 2;
	return lcp[k] = min(
		stu(i, x, 2 * k + 1, l, m),
		stu(i, x, 2 * k + 2, m, r)
	);
}
void stu(int i, int x){
	stu(i, x, 0, 0, n - 1);
}

int rmq(int a, int b, int k, int l, int r){
	if(r <= a || b <= l){
		return inf;
	}
	if(a <= l && r <= b){
		return lcp[k];
	}
	int m = (l + r) / 2;
	return min(
		rmq(a, b, 2 * k + 1, l, m),
		rmq(a, b, 2 * k + 2, m ,r)
	);
}
int rmq(int a, int b){
	return rmq(a, b, 0, 0, n - 1);
}

V rs(vector<P>& v){
	vector<V> a(n + 1, V());
	rep(i, n){
		a[v[i].second + 1].push_back(i);
	}
	vector<V> b(n, V());
	for(V& x: a){
		for(int i: x){
			b[v[i].first].push_back(i);
		}
	}
	V c(n);
	int cnt = 0;
	for(V& x: b){
		rep(i, x.size()){
			c[x[i]] = i == 0 || v[x[i - 1]].second < v[x[i]].second ? cnt : c[x[i - 1]];
			++cnt;
		}
	}
	return c;
}

void pp(){
	string v = t;
	sort(v.begin(), v.end());
	rep(i, n){
		sa[0][i] = lower_bound(v.begin(), v.end(), t[i]) - v.begin();
	}
	for(int i = 1; i <= 19; ++i){
		int k = 1 << i - 1;
		vector<P> s;
		rep(j, n){
			s.push_back(P(sa[i - 1][j], j + k < n ? sa[i - 1][j + k] : -1));
		}
		V v = rs(s);
		rep(j, n){
			sa[i][j] = v[j];
		}
		/*
		vector<P> v = s;
		sort(v.begin(), v.end());
		rep(j, n){
			sa[i][j] = lower_bound(v.begin(), v.end(), s[j]) - v.begin();
		}
		*/
	}

	rep(i, n){
		isa[sa[19][i]] = i;
	}

	int l = 0;
	rep(i, n){
		int r = sa[19][i];
		if(r == n - 1){
			l = 0;
			continue;
		}
		int j = isa[r + 1];
		while(i + l < n && j + l < n && t[i + l] == t[j + l]){
			++l;
		}
		stu(r, l);
		l = max(l - 1, 0);
	}
}

bool srch(const string& p){
	int m = p.size();

	int h = 0;
	while(isa[0] + h < n && h < m && t[isa[0] + h] == p[h]){
		++h;
	}

	int l = 0;
	int r = n;
	bool b = true;
	while(r - l > 1){
		int k = (l + r) / 2;
		if(b){
			int c = rmq(l, k);
			if(c > h){
				l = k;
			}
			else if(c < h){
				r = k;
				continue;
			}
			else{
				while(isa[k] + h < n && h < m && t[isa[k] + h] == p[h]){
					++h;
				}
				if(isa[k] + h == n){
					l = k;
				}
				else if(h == m){
					return true;
				}
				else{
					if(t[isa[k] + h] < p[h]){
						l = k;
					}
					else{
						r = k;
					}
				}
			}
		}
		else{
			int c = rmq(k, r);
			if(c > h){
				r = k;
			}
			else if(c < h){
				l = k;
				continue;
			}
			else{
				while(isa[k] + h < n && h < m && t[isa[k] + h] == p[h]){
					++h;
				}
				if(isa[k] + h == n){
					l = k;
				}
				else if(h == m){
					return true;
				}
				else{
					if(t[isa[k] + h] < p[h]){
						l = k;
					}
					else{
						r = k;
					}
				}
			}
		}
		b = l == k;
	}
	return isa[l] + m <= n && string(t, isa[l], m) == p;
}

int main(){
	cin >> t >> q;
	n = t.size();
	rep(i, q){
		cin >> p[i];
	}

	pp();

	rep(i, q){
		cout << srch(p[i]) << endl;
	}
	return 0;
}