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


class StringSearch {
	const int n;
	string S;
	vector<int> SA, Rank;
public:
	StringSearch(const string &S_)
		: n(S_.size()), S(S_), SA(n + 1), Rank(n + 1)
	{
		for (int i = 0; i <= n; i++) {
			SA[i] = i;
			Rank[i] = i < n ? S[i] : -1;
		}

		vector<int> tmp(n + 1);
		for (int k = 1; k <= n; k *= 2) {
			auto Compare_SA = [=](int i, int j) {
				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;
				}
			};
			sort(SA.begin(), SA.end(), Compare_SA);

			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];
			}
		}
	}

	bool Contain(const string &T) {
		int a = 0, b = n;
		while (b - a > 1) {
			int c = (a + b) / 2;
			if (S.compare(SA[c], T.length(), T) < 0) a = c;
			else b = c;
		}
		return S.compare(SA[b], T.length(), T) == 0;
	}
};

int main()
{
	int Q;
	string T, P;
	cin.sync_with_stdio(false);
	cin >> T;
	StringSearch SS(T);
	cin >> Q;
	while (Q--) {
		cin >> P;
		cout << SS.Contain(P) << endl;
	}
	return 0;
}