#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

class SuffixArray{
	private:
		int n;
		vector<int> rank;
	public:
		string s;
		vector<int> idx;
		SuffixArray(string& s) : n(s.size()), rank(s.size() + 1), s(s), idx(s.size() + 1) {
			rep(i,n + 1){
				idx[i] = i;
				rank[i] = i < n ? s[i] : -1;
			}

			int k;
			auto comp = [&](const int i, const int j) -> bool {
				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;
				}
			};

			vector<int> tmp(n + 1);
			for (k = 1; k <= n; k*=2) {
				sort(all(idx), comp);

				tmp[idx[0]] = 0;
				range(i,1,n + 1){
					tmp[idx[i]] = tmp[idx[i - 1]] + (comp(idx[i - 1], idx[i]) ? 1 : 0);
				}
				rank = tmp;
			}
		}
		bool contain(string& t){
			int right = n, left = 0;
			while(right - left > 1){
				int mid = (right + left) / 2;
				if(s.substr(idx[mid], t.size()) < t) left = mid;
				else right = mid;
			}
			return s.substr(idx[right], t.size()) == t;
		}
};

int main(){
	string s;
	int n;
	cin >> s >> n;

	SuffixArray suf(s);
	rep(i,n){
		string a;
		cin >> a;
		cout << suf.contain(a) << endl;
	}
}

