#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <new>
#include <deque>
#include <functional>
using namespace std;
 
template <class T>
struct myalloc{
	using value_type = T;
 
	static const int num = 70;
	static int k;
	static deque<vector<char>> dq;
 
	myalloc(){}
	template <class U>
	myalloc(const myalloc<U> &){}
 
	T* allocate(size_t n){
		if(k >= num || dq.empty()){
			dq.emplace_back(num * sizeof(T));
			k = 0;
		}
		return reinterpret_cast<T*>(&dq.back()[k++ * sizeof(T)]);
	}
 
	void deallocate(T*, size_t){}
};
 
template <class T>
int myalloc<T>::k;
template <class T>
deque<vector<char>> myalloc<T>::dq;
 
struct node{
	int fail;
	bool vis;
	map<char,int,less<char>,myalloc<char>> nxt;
};
 
 
string input(){
	static char buf[1000010];
	buf[0] = 0;
	scanf("%s", buf);
	return buf;
}
 
int main(){
	vector<node> trie(1);
	trie[0].fail = -1;

	trie.reserve(1000010);
 
	string t = input();
	int q;
	scanf("%d", &q);
	vector<int> idx(q);
	for(int i = 0; i < q; ++i){
		string p = input();
		int u = 0;
		for(char c : p){
			if(!trie[u].nxt.count(c)){
				trie[u].nxt.emplace(c, trie.size());
				trie.emplace_back();
			}
			u = trie[u].nxt[c];
		}
		idx[i] = u;
	}
 
	vector<int> bfs;
	bfs.push_back(0);
	int k = 0;
	while(k < (int)bfs.size()){
		int u = bfs[k++];
		for(const auto &pr : trie[u].nxt){
			char c = pr.first;
			int v = pr.second;
			bfs.push_back(v);
 
			int f = trie[u].fail;
			while(f >= 0 && !trie[f].nxt.count(c)){
				f = trie[f].fail;
			}
			trie[v].fail = f >= 0 ? trie[f].nxt[c] : 0;
		}
	}
 
	int r = 0;
	for(char c : t){
		while(r >= 0 && !trie[r].nxt.count(c)){
			r = trie[r].fail;
		}
		r = r >= 0 ? trie[r].nxt[c] : 0;
		trie[r].vis = true;
	}
 
	for(int i = bfs.size(); --i; ){
		int u = bfs[i];
		if(trie[u].vis){
			trie[trie[u].fail].vis = true;
		}
	}
 
	for(int i = 0; i < q; ++i){
		printf("%d\n", +trie[idx[i]].vis);
	}
}